developer tip

Virtualenv로 pip를 통해 설치할 수 없습니다.

optionbox 2020. 11. 26. 08:11
반응형

Virtualenv로 pip를 통해 설치할 수 없습니다.


다음은 실행할 때 발생하는 오류입니다 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$ 

공백이없는 경로 내에서 virtualenv 환경을 만듭니다. 이것이 일어나는 이유입니다.

환경을 만들 때 bin디렉터리를 설정합니다 . bin디렉토리에는 환경과 관련된 모든 실행 파일이 있습니다. 일부는 스크립트입니다. 아시다시피 해시 뱅은 스크립트를 실행하는 데 사용할 인터프리터를 시스템에 알리는 데 사용됩니다. 스크립트 상단에서 자주 볼 수 있습니다.

#!/usr/bin/env python

스크립트가에 있으면 /tmp/test.py이 명령을 실행하여 스크립트를 실행하도록 시스템에 지시합니다.

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

귀하의 경우 virtualenv는 다음과 같은 스크립트를 생성합니다.

#!/tmp/oh no/bin/python

시스템이이를 실행하려고하면 /tmp/oh인수를 사용 하여 명령을 실행하려고합니다 . 존재하지 않으므로 실패합니다.no/bin/python/tmp/test.py/tmp/oh


이 문제를 겪는 사람들을 위해 나는 공백을 사용하지 않고도 경로의 길이가 문제를 일으킬 수 있음을 발견했습니다 (Ubuntu 12.04).

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

실패했지만

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

잘 작동했습니다. 아래 Alex의 의견을 참조하십시오.


pip 다음과 같은 경우 명령이 작동하지 않습니다.

  • 시스템에 pip를 설치하지 않았습니다. (virtualenv에서 사용하기 전에 먼저 시스템에 pip를 설치해야합니다 pip. Ubuntu에 설치하려면 명령 sudo apt-get install python-pip또는을 사용하십시오. sudo apt-get install python3-pip)
  • 가상 환경 폴더 경로에 공백이 있습니다 . (예 : / home / username / my 폴더 이름 (공백 / newvirtualenv 포함))
  • 가상 환경 폴더의 경로가 너무 깁니다. 예 : / home / username / mytoobigpath / somefolder / anotherfolder / someanotherfolder / someanotherfolderagain / myvirtualenv. (더 작은 이름으로 상위 폴더의 이름을 바꾸십시오)

어떤 이유로 폴더 이름을 변경하거나 경로를 변경할 수없는 경우 명령을 yourvirtualenvfolder/bin사용하여 이동 cd한 다음 ./python pip install packagename.


icktoofay는 원인에 대해 정확합니다.

공백이있는 디렉토리에서 virtualenv와 함께 pip를 사용하려면을 편집 /path/to/env/bin/pip하여 맨 위에있는 shebang을 #!/usr/bin/env python(또는 #!/usr/bin/env pypypypy를 사용하는 경우) 대체하십시오 .

virtualenv는 virtualenv에서 정의한를 /usr/bin/env python참조하도록 환경을 변경합니다 python.


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

Solution: In /usr/local/bin/pip, replace first line #!/usr/local/bin/python2.7 with your actual Python path #!/root/installer/Python-2.7.5/python


I had a very similar issue on my Windows 7 machine and struggled couple of days with that. Both paths, to my python distribution and to my VE had spaces in it. 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:

  1. Make sure I used pip to install virtualenv and it's the latest version (pip-7.1.0). Result: failure.
  2. Install win32api. Result: failure (although there was some error at the very end of installation process).
  3. Try to install my VE in a path without spaces. Result: failure.
  4. Reinstall my Anaconda python distribution to the path that didn't contain the "[" and "]" brackets. VE had spaces in the path. Result: failure.
  5. Reinstall my Anaconda python distribution to the path that also didn't contain any spaces. The VE folder still had spaces in the path. Result: success!

So at least the Anaconda (python) installation simple, non space-pollutted path was crucial. Maybe win32api installation was also important. Not sure.


I found this from a Google search while experiencing the same problem and found this to be 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 does come with some caveats, so be sure to read the documentation to understand the implications:

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

You need to use the same syntax to relocate the virtualenv as you did when creating it, 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 result in #!/usr/bin/env python2.7 (at least on my local environment)...

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

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

It seems my folder content has same subfolder names as generated by virtualenv, such as bin, lib etc. And after copy in my files, reactivate the environment let virtualenv to update new information.


On Python 3.7 I didn't have any issues with this but when I had to use Python 3.6 I did have an issue. The most easy work-around I found on Github was this:

Instead of:

pip install -r requirements.txt

I use:

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

So you actually directly point to the pip file within your virtual environment directory. Of course you need to activate it first before trying this. Hope this helps someone who comes here!

참고URL : https://stackoverflow.com/questions/7911003/cant-install-via-pip-with-virtualenv

반응형