简体   繁体   中英

virtualenv not running after install

I have

$ which virtualenv
$ 

and

$ virtualenv --version
-bash: virtualenv: command not found

I have tried to add virtualenv to my PATH, but I don't really know what I'm doing. Here is the PATH

$PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/MAMP/Library/bin:/usr/local/mysql/bin:/usr/local/bin/virtualenv:/usr/local/bin/virtualenv/virtualenv.py

As you might expect, the problem persists.

What exactly do I need to do to fix this?

I am pretty sure I need to add virtualenv to PATH somehow, but what is "virtualenv" ?

Does that mean the .py file, or if there are multiple copies, where should I be looking? If no one can provide a solution to this problem, as least a clarification of what the problem is for me would help with troubleshooting.

I used

sudo easy_install virtualenv

to install, which yielded

Using /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv-13.1.2-py2.7.egg

Thanks.

Usually, installing virtualenv will create a thin wrapper script somewhere like /usr/local/bin/virtualenv . I don't know why yours didn't; but it's so simple that you can copy/paste it manually to $HOME/bin/virtualenv or wherever. (You don't seem to have $HOME/bin in your PATH so you'd have to add that then, or put it somewhere like /usr/local/bin if you have the permissions and feel that you know what you are doing ... but I'm getting the feeling you should not.)

#!/usr/bin/env python
import virtualenv
virtualenv.main()

Alternatively, put something like alias virtualenv='python /that/long/path/to/virtualenv.py' in your .bash_profile or similar.

These are simple workarounds; figuring out after the fact why the installation failed without more details about your system (including the output from easy_install when you ran it) is probably too complex for a Stack Overflow question.

Incidentally, the last component of your PATH is wrong. The PATH variable is a colon-separated list of directories ; adding an individual file to the PATH will not work. In theory, you could change it so that the parent directory is on the path, and always use virtualenv.py instead of just virtualenv , but I don't think that's a proper fix (and actually I'm not sure whether it will work. Looks like it will if you have a version which is similar to mine, but what if you don't?).

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