Cannot install via pip using Virtualenv

The following is the error I get when starting 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$ 
+60
python pip
Oct 27 2018-11-11T00:
source share
9 answers

Create your virtual environment on the go without spaces. This is why this happens:

When you create the environment, it sets the bin directory. In this bin all executable files related to the environment. Some of them are scripts. As you may know, hashbangs are used to tell the system which interpreter to use to run the script. You can often see this at the top of the scripts:

 #!/usr/bin/env python 

If the script is in /tmp/test.py , which tells the system to execute this command to execute the script:

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

In your case, virtualenv creates scripts like this:

 #!/tmp/oh no/bin/python 

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

+122
Oct 27 '11 at 2:19
source share

For those facing this problem, I found that path lengths can also cause problems without using spaces (Ubuntu 12.04):

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

failed but

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

worked fine, see Alex comment below

+21
Jun 04 '15 at 7:55
source share

The pip command will not work if:

  • You did not install pip on your system. (you must first install pip on your system before using it on virtualenv. To install pip on Ubuntu, use the sudo apt-get install python-pip or sudo apt-get install python3-pip )
  • The path to your virtual environment folder contains spaces (and) . (Example: / home / username / name of my folder with spaces / newvirtualenv)
  • The path to your virtual environment folder is too long. Example: / home / username / mytoobigpath / somefolder / anotherfolder / someanotherfolder / someanotherfolderagain / myvirtualenv. (Try renaming parent folders with smaller names)

If for some reason you cannot rename folders or change the path, yourvirtualenvfolder/bin (using the cd ), then try ./python pip install packagename .

+17
Dec 28 '16 at 5:12
source share

icktoofay is correct regarding the cause.

To use pip with virtualenv in the spaces directory, edit /path/to/env/bin/pip , replacing shebang at the top with #!/usr/bin/env python (or #!/usr/bin/env pypy if you use pypy )

Note that virtualenv modifies your environment such that /usr/bin/env python refers to python defined by virtualenv.

+14
Dec 04 '13 at 7:38
source share

I got the same error in RedHat. Python 2.7.3 is configured and made by itself. [root @Ifx installer] # pip install Django - bash: / usr / local / bin / pip: /usr/local/bin/python2.7: bad interpreter: permission denied

In / usr / local / bin / pip replace the first line #! / Usr / local / bin / python2.7 with your actual Python path #! / Root / installer / Python-2.7.5 / python

+1
May 22 '14 at 14:19
source share

I had a very similar problem on my Windows 7 machine and struggled with it for a couple of days. Both paths to my python distribution and to my VE had spaces . A couple of months before it worked fine. I found the following note on virtualenv website:

 **Windows Notes** [...] To create a virtualenv under a path with spaces in it on Windows, you'll need the win32api library installed. 

The following steps lead me to success:

  • Make sure I used pip to install virtualenv and this is the latest version (pip-7.1.0). Result: failure .
  • Install win32api. Result: failure (although there was some error at the very end of the installation process).
  • Try installing my VE along the way without spaces. Result: failure .
  • Reinstall the python Anaconda distribution to a path that does not contain the brackets "[" and "]". VE had gaps along the way. Result: failure .
  • Reinstall the Anaconda python distribution to a path that also contains no spaces. There were still spaces in the VE folder. Result: success!

So at least the simple installation of Anaconda (python) , a non-space path was key. . Perhaps installing win32api is also important. Not sure.

0
Aug 13 '15 at 1:54
source share

I found this from a Google search, experiencing the same problem, and found it very useful. virtualenv now has a --relocatable flag that will rewrite the shebang command to #!/usr/bin/env <the_python_version_you_used_to_create_the_virtualenv> . It comes with some caveats, so be sure to read the documentation to understand the consequences:

https://virtualenv.pypa.io/en/stable/userguide/#making-environments-relocatable

You need to use the same syntax to move virtualenv the same as when creating, otherwise the python version may be overwritten. This will work as expected ...

 virtualenv --python=python3.5 env-test virtualenv --relocatable --python=python3.5 env-test 

whereas this will lead to #!/usr/bin/env python2.7 (at least in my local environment) ...

 virtualenv --python==python3.5 env-test virtualenv --relocatable env-test 
0
Apr 6 '17 at 12:53 on
source share

In my case, deactivate the environment, and source bin/activate works again.

It seems that the contents of my folder have the same subfolder names as with virtualenv , like bin, lib, etc. And after copying to my files, reactivate the environment so that virtualenv updates the new information.

0
Sep 13 '18 at 13:38
source share

On Python 3.7, I had no problems with this, but when I had to use Python 3.6, I had problems. The simplest workaround I found on Github was this:

Instead:

 pip install -r requirements.txt 

I use:

 python env/bin/pip install -r requirements.txt 

That way, you are actually directly pointing to the pip file in the directory of your virtual environment. Of course, you need to activate it before trying this. Hope this helps someone coming here!

0
Nov 12 '18 at 15:44
source share



All Articles