2

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?
Leonard
  • 2,978
  • 6
  • 21
  • 42
  • 1
    You need to use `pip3` (as in your other question). `pip` points to 2.7. Virtualenvwrapper works great once you get past the initial setup. – DaveStSomeWhere Sep 05 '19 at 04:05
  • 1
    @DaveStSomeWhere Sorry that does not solve the problem. It simply installs it in 3.7/bin – Leonard Sep 05 '19 at 05:12

1 Answers1

5

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.

alfonso
  • 884
  • 17
  • 31
  • pip install virtualenvwrapper does not allow me to run the command. – Leonard Sep 05 '19 at 03:29
  • ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/virtualenvwrapper-4.8.4-py3.7-nspkg.pth' Consider using the `--user` option or check the permissions. – Leonard Sep 05 '19 at 03:30
  • Hmm... interesting. I guess it wouldn't make sense for the virtualenv people to let you install at the system level. If you really really really want to though, maybe try with sudo. That'll make their heads explode. It kind of defeats one of the purposes of a virtual environment - not polluting your system level install – alfonso Sep 05 '19 at 03:31
  • I am trying all different combinations..I will post it on another thread. It will be great if you could help me. I couldn't get any work done for two days because of this – Leonard Sep 05 '19 at 03:32
  • Try that: https://stackoverflow.com/questions/31133050/virtualenv-command-not-found – alfonso Sep 05 '19 at 03:34
  • I should have clarified myself. So I did see that and added to the path. However, I want to figure out if there is a way to avoid this from the beginning, since many other people are not facing the same issue as I am. – Leonard Sep 05 '19 at 05:14
  • OK, no problem. I imagine you have your reasons, but in general, it's bad form to install packages at the system level. If you ever find yourself using sudo pip install, then you're playing with fire. Sorry I couldn't help with your question. – alfonso Sep 05 '19 at 15:13
  • 1
    You did help me with just moving on with the above solution. I really appreciate your effort and help! Thanks for the kind answer. – Leonard Sep 05 '19 at 15:26