Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install via pip with Virtualenv

Tags:

python

pip

Below is the error I get when I run pip:

serkan$ rm -r mysite serkan$ pwd /Users/serkan/Desktop/Python Folder serkan$ virtualenv mysite  New python executable in mysite/bin/python Installing setuptools............done. Installing pip...............done. serkan$ source mysite/bin/activate (mysite)serkan$ pip install pinax -bash: /Users/serkan/Desktop/Python Folder/mysite/bin/pip: "/Users/serkan/Desktop/Python: bad interpreter: No such file or directory (mysite)serkan$ python pip install pinax python: can't open file 'pip': [Errno 2] No such file or directory (mysite)serkan$ python pip install Pinax python: can't open file 'pip': [Errno 2] No such file or directory (mysite)serkan$ python pip install Pinax python: can't open file 'pip': [Errno 2] No such file or directory (mysite)serkan$ python pip install Pinax python: can't open file 'pip': [Errno 2] No such file or directory (mysite)serkan$ python pip  python: can't open file 'pip': [Errno 2] No such file or directory (mysite)serkan$ pip -bash: /Users/serkan/Desktop/Python Folder/mysite/bin/pip: "/Users/serkan/Desktop/Python: bad interpreter: No such file or directory (mysite)serkan$ pip install Pinax -bash: /Users/serkan/Desktop/Python Folder/mysite/bin/pip: "/Users/serkan/Desktop/Python: bad interpreter: No such file or directory (mysite)serkan$  
like image 829
shaytac Avatar asked Oct 27 '11 02:10

shaytac


People also ask

How do I enable pip virtual env?

To install virtualenv, just use pip install virtualenv . To create a virtual environment directory with it, type virtualenv /path/to/directory . Activating and deactivating the virtual environment works the same way as it does for virtual environments in Python 3 (see above).

What is pip install virtualenv?

pip is a tool for installing packages from the Python Package Index. virtualenv is a tool for creating isolated Python environments containing their own copy of python , pip , and their own place to keep libraries installed from PyPI.


2 Answers

Create your virtualenv environment within a path without spaces. This is why it is happening:

When you create an environment, it sets up a bin directory. In that bin directory are all the executables relating to the environment. Some are scripts. As you may know, hashbangs are used to tell the system what interpreter to use to run the script. You may see this at the top of scripts often:

#!/usr/bin/env python 

If the script is at /tmp/test.py, that tells the system to run this command to execute the script:

/usr/bin/env python /tmp/test.py 

In your case, virtualenv is creating scripts like this:

#!/tmp/oh no/bin/python 

When the system tries to execute that, it will try to execute the command /tmp/oh with the arguments no/bin/python and /tmp/test.py. /tmp/oh does not exist, so it fails.

like image 165
icktoofay Avatar answered Oct 06 '22 23:10

icktoofay


For those running into this issue, I discovered that the length of the path could cause issues as well, without using any spaces (Ubuntu 12.04):

virtualenv /home/user/some/very/longer/path/without/spaces/etc/venv 

failed, while

virtualenv /home/user/some/very/long/path/without/spaces/etc/venv 

worked just fine, see Alex's comment below

like image 33
Hedde van der Heide Avatar answered Oct 07 '22 00:10

Hedde van der Heide