Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: pip tries to install to /bin directory

Tags:

python

macos

pip

I installed python with brew install python

which pip
/usr/local/bin/pip

my PYTHONPATH shows /usr/local/lib/python2.7/site-packages/

However, when I try to install something with pip, it goes to the /bin/ directory as shown below. I want things installed to /usr/local/lib/python2.7/site-packages/. How do I fix this?

pip install virtualenv
Downloading/unpacking virtualenv
  Downloading virtualenv-1.11.6-py2.py3-none-any.whl (1.6MB): 1.6MB downloaded
Installing collected packages: virtualenv
Cleaning up...
Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
{....}
  File "/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/util.py", line 384, in write_binary_file
    with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/bin/virtualenv'



$ pip list
pip (1.5.6)
setuptools (5.4.2)
wsgiref (0.1.2)


$pip show setuptools
---
Name: setuptools
Version: 5.4.2
Location: /usr/local/lib/python2.7/site-packages/setuptools-5.4.2-py2.7.egg
Requires:

So pip already has the basic packages installed to site-packages. However, running the same exact pip to install virtualenv tries to install to /bin/.

like image 351
imagineerThat Avatar asked Dec 14 '14 01:12

imagineerThat


People also ask

How to install Pip in Python?

There are two ways to install Python packages: Using a requirements.txt file that defines the required packages and their version numbers. But before we start, let’s make sure pip itself is installed! Good news; chances are that Pip is already present on your system. Most Python installers also install Pip.

What is ~/.local/bin and why does pip use it?

The short answer is that ~/.local/bin is the default value of Python's User Script Directory and that pip may install executables into this directory if it performs a user-local installation. It may also install files into other subdirectories of ~/.local, which is the default value of the User Base Directory.

Where does pip install lib and bin files?

Newer versions of pip (8 or later) can directly use the --prefix option: where $PREFIX_PATH is the installation prefix where lib, bin and other top-level folders are placed.

What is ~/.local/bin used for in Python?

Show activity on this post. The short answer is that ~/.local/bin is the default value of Python's User Script Directory and that pip may install executables into this directory if it performs a user-local installation. It may also install files into other subdirectories of ~/.local, which is the default value of the User Base Directory.


2 Answers

I was running into this same issue when trying to install virtualenv and flask. Turns out I had a .pydistutils.cfg file in my home directory. I remember placing this there not too long ago as a work around for installing something else. Once I removed this file, running pip install continued working as expected.

like image 120
Cameron Gagnon Avatar answered Sep 19 '22 18:09

Cameron Gagnon


For me, there was a setup.cfg file with the following code

[install]
prefix=

Removing the file fixed it for me.

like image 28
coding_idiot Avatar answered Sep 20 '22 18:09

coding_idiot