6

I've got a Mac which has python installed and virtualenvwrapper installed. I'm trying to create a new environment by running:

mkvirtualenv Test

To which I get the following error:

New python executable in /Users/sidharthnayyar/.virtualenvs/Test/bin/python
Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
        exec code in run_globals
    File "/Library/Python/2.7/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
        from stevedore import ExtensionManager
ImportError: No module named stevedore

I have python installed here:

$ which -a python
    /usr/local/bin/python
    /usr/bin/python

If I try sudo pip install stevedore then it says its already installed with some warnings:

sudo /usr/local/bin/pip install stevedore
The directory '/Users/sidharthnayyar/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/sidharthnayyar/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied (use --upgrade to upgrade): stevedore in ./Library/Python/2.7/lib/python/site-packages
Requirement already satisfied (use --upgrade to upgrade): pbr>=1.6 in /Library/Python/2.7/site-packages (from stevedore)
Requirement already satisfied (use --upgrade to upgrade): six>=1.9.0 in ./Library/Python/2.7/lib/python/site-packages (from stevedore)

If I try sudo -H pip install stevedore then I get the following errors:

sudo -H /usr/local/bin/pip install stevedore

Collecting stevedore
    Using cached stevedore-1.18.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): pbr>=1.6 in /Library/Python/2.7/site-packages (from stevedore)
Collecting six>=1.9.0 (from stevedore)
    Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six, stevedore
    Found existing installation: six 1.4.1
        DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
        Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
    File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
        status = self.run(options, args)
    File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 317, in run
        prefix=options.prefix_path,
    File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 736, in install
        requirement.uninstall(auto_confirm=True)
    File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 742, in uninstall
        paths_to_remove.remove(auto_confirm)
    File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
        renames(path, new_path)
    File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
        shutil.move(old, new)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
        copy2(src, real_dst)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
        copystat(src, dst)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
        os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-NOex2K-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

If I create a .bash_profile and put into it:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

and reload a terminal window then I get the following error:

source ~/.bash_profile
Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
    File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
        exec code in run_globals
    File "/Library/Python/2.7/site-packages/virtualenvwrapper/hook_loader.py", line 16, in <module>
        from stevedore import ExtensionManager
ImportError: No module named stevedore
virtualenvwrapper.sh: There was a problem running the initialization hooks. 

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python and that PATH is
set properly.

Curious and curiouser.

Any suggestions on what's going wrong and how to fix this?

Thanks Sidharth

SKN
  • 95
  • 1
  • 6
  • Possible duplicate: http://stackoverflow.com/questions/24537174/how-do-i-solve-this-error-message-error-virtualenvwrapper-could-not-find-virtu ? – sberry Oct 26 '16 at 15:47
  • Hi, thanks for that. Unfortunately I've tried all suggestions on that and it doesn't seem to work for me. So the first answer says the ~ in the PATH was causing an issue. But my $PATH is `/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin`. Another answer says that I need to put the path of where the virtualenv is installed into my PATH. But virtualenv is in /usr/local/bin - and my PATH, as mentioned above, does have that path. Third answer said the python path is in different location. So I changed bash_profile (in question above now) to specify python path but it gives another error – SKN Oct 27 '16 at 09:09
  • python on the mac is here: `which -a python` `/usr/local/bin/python` `/usr/bin/python` which is what I set my VIRTUALENVWRAPPER_PYTHON to in the bash_profile (updated question with those details) but it gives similar error. 4th answer says he had virtualenv installed via easy_install so he had to install it via pip. I don't know how virtualenv was installed on my machine (or how I can check) but it was in /usr/local/bin so I uninstalled with `sudo /usr/local/bin/pip uninstall virtualenv` and then installed via `sudo /usr/local/bin/pip install virtualenv` but didn't help. – SKN Oct 27 '16 at 09:15
  • Last suggestion said he didn't have it installed, but I do have it. Any other suggestions? – SKN Oct 27 '16 at 09:16

3 Answers3

4

I was very confused with this problem, too. And I have solved it by uninstalling the old stevedore and reinstall it.

sudo pip uninstall stevedore
sudo pip install stevedore
Zhenhui
  • 41
  • 2
1

Looks like you managed to install virtualwrapper without stevedore, which is a dependency. Try installing it.

pip install stevedore
hvwaldow
  • 1,296
  • 1
  • 11
  • 13
  • Hi, thanks for the response (and sorry if you got lots of notifications about edits on this comment!!). It seems stevedore is already installed - but with some warnings (on sudo pip install) and errors (on sudo -H pip install). Maybe it's a permission issue? (I've updated my main question with the details of the pip install as it seems the formatting via comments are limited). Thank you! – SKN Oct 27 '16 at 07:38
  • Ok that is messed up. Your installation attempt with sudo [without -H] shows that it is installed for the user. That it doesn't work with sudo -H presumably is a "feature" of MacOS and probably the fix for that is here: [http://stackoverflow.com/a/32661637/6930916]. My personal strategy to deal with that mess is to have the essentials (in this case virtualenv, virtualwrapper) installed on the system level, everything else in the virtualenv where it is needed, and not install anything on the user level (don't use pip install --user). – hvwaldow Oct 27 '16 at 09:19
  • If you want to follow that path, clean out everything under $HOME/Library/Python, get proper admin rights, and install virtualwrapper for the system (sudo -H pip install). Otherwise you might want to have a look at environment variable [PYTHONPATH](https://docs.python.org/3/using/cmdline.html#envvar-PYTHONPATH) so that the modules installed for User are found. – hvwaldow Oct 27 '16 at 09:20
  • So I did a search for stevedore and I got `sudo find / -name stevedore` `/Users/sidharthnayyar/Library/Python/2.7/lib/python/site-packages/stevedore`. Could this be the issue? I.e. it's not in /usr/local/bin? – SKN Oct 27 '16 at 09:48
  • Sorry I didn't see your message until after I had posted the comment. Sorry, I'm a newbie on Mac but when you saying "clean out" I presume it's just a case of deleting? Or can I do a pip uninstall (/usr/local/bin/pip?)? I checked System Preferences and apparently my account is an admin - do you mean do what that stackoverflow answer suggested and "csrutil disable"? They also said not to do it unless you are not a newbie! .. it's got me worried! :) – SKN Oct 27 '16 at 10:16
  • To solve your actual problem I would do the "csrutil disable" thing and then "sudo -H pip install --upgrade --force-reinstall virtualenvwrapper". I would risk it ;). You can enable csrutil again after that. Yes, to get rid of the stuff installed for a user "pip uninstall" should work (executed as user, not with sudo). – hvwaldow Oct 27 '16 at 11:14
0

with python 2.7 sudo pip install stevedore

alfonsoolavarria
  • 1,141
  • 11
  • 11