简体   繁体   中英

pip installs packages in Library/Python/2.7/bin

I am following this tutorial to install virtualenvwrapper https://realpython.com/python-virtual-environments-a-primer/#managing-virtual-environments-with-virtualenvwrapper

However, I just can't get mine working.

When I do pip install virtualenvwrapper --user I get the following warning.

Installing collected packages: virtualenv, pbr, six, stevedore, virtualenv-clone, virtualenvwrapper
  WARNING: The script virtualenv is installed in '/Users/user1/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script pbr is installed in '/Users/user1/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script virtualenv-clone is installed in '/Users/user1/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

So I added the following to my .bash_profile and now it can find the package.

"/Users/user1/Library/Python/2.7/bin:$PATH"

but I just don't understand why this extra step is necessary in my environment when everyone else seems to be fine with package just being directly installed to /local/bin .

These are where my python2 and pip are with no symlink.

admins-MacBook-Pro:~ user1$ which python
/usr/bin/python
admins-MacBook-Pro:~ user1$ which pip
/usr/local/bin/pip

Question

  1. Why is my pip installing stuff on /Users/user1/Library/Python/2.7/bin when most people seem to be fine with /usr/local/bin/ ?
  2. Is there a way for me to avoid this issue? How can I cleanly set up my environment so that all packages are installed in /usr/local/bin?

Most people use virtual environments to maintain different versions of packages. This is so your various codebases don't clash with each other. A second reason to use virtual environments is so that you don't pollute your system install of Python.

Adding the --user flag will install packages to Python at the user level, and not the system level. If you make it a habit to install to the user level, then you'll avoid problems where you update package versions that the system needs.

Once you're working in a virtual environment, then anything you install will be in your environment. However, the initial package install of virtualenv has to be installed somewhere -- on the machine's user level.

What is the purpose "pip install --user ..."?

I'm editing the answer. You shouldn't use sudo or try to install at the system level. The warnings are clear about where your virtualenv is installed and what directories you need to add to your PATH. I recommend you add those directories as described here: https://apple.stackexchange.com/a/358873/249870

Edit your ~/.bash_profile file by adding this line:
export PATH="/Users/user1/Library/Python/2.7/bin:$PATH"

Next, on the command line, source the file:
$ source ~/.bash_profile

That should do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM