Can't set up virtualenv python: No module named pip - python

I am trying to set up a python environment on a remote computer via ssh (with no root access). I am following the instructions below:
Download the virtualenv script:
wget -O /tmp/virtualenv.py https://raw.github.com/pypa/virtualenv/master/virtualenv.py
Run the virtual env script
python /tmp/virtualenv.py $HOME/pyenv/
which will setup the environment in the "pyenv" directory in your $HOME space
Update the environment
If you are using bash (I hope you do), then you should add:
. $HOME/pyenv/bin/activate
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/ioa//lib:/usr/local/lib64
to your .bashrc
And when I run python /tmp/virtualenv.py $HOME/pyenv/, I am getting the error
New python executable in /home/lht26/pyenv/bin/python
Cannot find a wheel for setuptools
Cannot find a wheel for pip
Installing setuptools, pip, wheel...
Complete output from command /home/lht26/pyenv/bin/python - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
ImportError: No module named pip
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/tmp/virtualenv.py", line 2328, in <module>
main()
File "/tmp/virtualenv.py", line 713, in main
symlink=options.symlink)
File "/tmp/virtualenv.py", line 945, in create_environment
download=download,
File "/tmp/virtualenv.py", line 901, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/tmp/virtualenv.py", line 797, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/lht26/pyenv/bin/python - setuptools pip wheel failed with error code 1
What should I do?

Here are the steps to run virtualenv.
First, install pip (pip3 if you have 3 version of python):
sudo apt-get install python-pip
Then run the following:
sudo pip install virtualenv
mkdir myproject
cd myproject
virtualenv venv
. venv/bin/activate

Related

AttributeError when running pip in virtualenv

I recently upgraded python from 2.7.6 to 2.7.9 using homebrew. I then tried to 'revirtualise' an existing virtual environment:
sudo virtualenv -p python2.7 existingvenv
But am getting this error:
Traceback (most recent call last):
File "venv.../bin/pip", line 7, in <module>
from pip import main
File "venv.../lib/python2.7/site-packages/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "venv.../lib/python2.7/site-packages/pip/log.py", line 8, in <module>
from pip import backwardcompat
File "venv.../lib/python2.7/site-packages/pip/backwardcompat/__init__.py", line 66, in <module>
from urllib2 import URLError, HTTPError
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 93, in <module>
import hashlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 2352, in <module>
main()
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 993, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 961, in install_wheel
'PIP_NO_INDEX': '1'
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 903, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/robertelliott...hflow-app/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
I also get the above error when running any pip install x inside the above active virtual environment.
I don't get the error when creating a new virtualenv:
$ virtualenv -p python2.7 newvenv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
New python executable in newenv/bin/python
Installing setuptools, pip...done.
Is there an old symlink or something inside the existing virtualenv causing the issue and how can I resolve this?
This is because of a new feature in Python, which wheel 0.24 is not compatible with. You'll find a folder called virtualenv_support containing base install files for setuptools, pip, and wheel under your Python 2.7 system install. There are a few solutions. The easiest is to just remove wheel-0.24* from the virtualenv_support folder. If you want to go a step farther, you could download version 0.26 of the wheel .whl file and replace it.
did you try:
sudo virtualenv --clear -p python2.7 existingvenv
?

Virtualenv venv fails with the following error

I'm new to Python development and I'm trying to instal virtualenv in my project directory.
However I have the following error:
Installing collected packages: pip, setuptools
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/commands/install.py", line 347, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_set.py", line 549, in install
**kwargs
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_install.py", line 754, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/req/req_install.py", line 963, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/wheel.py", line 234, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-6.0.8-py2.py3-none-any.whl/pip/wheel.py", line 212, in clobber
shutil.copyfile(srcfile, destfile)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 82, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip/__init__.py'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/Library/Python/2.7/site-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 993, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 961, in install_wheel
'PIP_NO_INDEX': '1'
File "/Library/Python/2.7/site-packages/virtualenv.py", line 903, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/alexandrurada...oard/venv/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 2
I installed pip with
easy_install pip
Then I installed virtualenv with
pip install virtualenv
Without any errors. However I'm still getting this. I didn't want to try it with sudo. Should I?
UPDATE: I installed them with sudo, and I got rid of this error. However another one when trying to install something with pip:
air:dashboard alexandrurada$ pip install flask
-bash: /usr/local/bin/pip: "path_here": bad interpreter: No such file or directory
UPDATE 2: The earlier error was because of a space inside a directory name. Looks like path doesn't work with such names.
Anyway, the error I'm getting now is
File "/usr/local/bin/pip", line 7, in <module>
from pip import main
ImportError: No module named pip
I checked my /usr/local/bin/pip and the file exists.
You need sudo pip install virtualenv to install virtualenv globally. When setting up your virtualenvs make sure you don't use sudo and that you activate your virtualenv before trying to install.
[Errno 13] Permission denied: means you don't have write permissions.
Install a newer version of pip and avoid using easy_install.
Download pip from: https://bootstrap.pypa.io/get-pip.py
and then run Python on it:
$ python get-pip.py
If you want to install pip to the global path, you likely want to run that last command with sudo. Without using sudo, pip will get installed for use with whatever Python interpreter is in your path.
From here, you can install virtualenv with pip:
$ pip install virtualenv
From your responses, it seems like you'd be best served by getting your system in a known state: Download that file, then run sudo python get-pip.py so you're running with a known-working pip install.

Error while making virtualenv with python3 interpeter on Mac OS 10.9

Mac OS X Version - 10.9.3
Pip version - pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)
Hello!
When I try to make a virtualenv with python3 interpeter I get this error:
air$ virtualenv python3.4 --python=/usr/local/bin/python3.4
Running virtualenv with interpreter /usr/local/bin/python3.4
Using base prefix '/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4'
New python executable in python3.4/bin/python3.4
Not overwriting existing python script python3.4/bin/python (you must use python3.4/bin/python3.4)
Installing setuptools, pip...
Complete output from command /Users/***/.virt...hon3.4/bin/python3.4 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/__init__.py", line 10, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/util.py", line 18, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/distlib/version.py", line 14, in <module>
File "/Library/Python/2.7/site-packages/virtualenv_support/pip-1.5.6-py2.py3-none-any.whl/pip/_vendor/distlib/compat.py", line 66, in <module>
ImportError: cannot import name 'HTTPSHandler'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/virtualenv.py", line 2338, in <module>
main()
File "/Library/Python/2.7/site-packages/virtualenv.py", line 824, in main
symlink=options.symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 992, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 960, in install_wheel
'PIP_NO_INDEX': '1'
File "/Library/Python/2.7/site-packages/virtualenv.py", line 902, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/***/.virt...hon3.4/bin/python3.4 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 1
Binaries:
air$ which python python3 pip openssl virtualenv
/usr/bin/python
/usr/local/bin/python3
/usr/local/bin/pip
/usr/bin/openssl
/usr/local/bin/virtualenv
Python3 was installed with brew install python3
Pip was installed with sudo easy_install pip
PATH:
air$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Please, help me, what i do wrong?
I found this related to my question, but how can i fix it on Mac OS?
UPD:
More info about system:
air$ pip3
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 7, in <module>
from pip import main
ImportError: No module named 'pip'
air$ cat /usr/local/bin/pip3
#!/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/bin/python3.4
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
You have to install openssl first, than python. So openssl support will work (python compiles with ssl support if openssl is available at install time.).
In addition to Mathias' answer, you also need to make sure that the following environment variables are set before compiling python3:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

Python 3.3.4 and virtualenv creation on Windows: ImportError: No module named 'pip'

I need virtualenv for Pyramid on XP.
pip installs fine and so does virtualenv
But when I try to create an instance directory, virtualenv bombs.
I uninstalled and re-installed virtualenv, but I keep getting the same problem.
Any ideas?
C:\>pip --version
pip 1.5.4 from C:\Python334\lib\site-packages (python 3.3)
C:\>virtualenv --version
1.11.4
C:\>virtualenv venv
Using base prefix 'C:\\Python334'
New python executable in venv\Scripts\python.exe
Installing setuptools, pip...
Complete output from command C:\venv\Scripts\python.exe -c "import sys, pip; s
ys...d\"] + sys.argv[1:]))" setuptools pip:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'pip'
----------------------------------------
...Installing setuptools, pip...done.
Traceback (most recent call last):
File "C:\Python334\lib\runpy.py", line 160, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python334\lib\runpy.py", line 73, in _run_code
exec(code, run_globals)
File "C:\Python334\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "C:\Python334\lib\site-packages\virtualenv.py", line 824, in main
symlink=options.symlink)
File "C:\Python334\lib\site-packages\virtualenv.py", line 992, in create_envir
onment
install_wheel(to_install, py_executable, search_dirs)
File "C:\Python334\lib\site-packages\virtualenv.py", line 960, in install_wheel
'PIP_NO_INDEX': '1'
File "C:\Python334\lib\site-packages\virtualenv.py", line 902, in call_subproc
ess
% (cmd_desc, proc.returncode))
OSError: Command C:\venv\Scripts\python.exe -c "import sys, pip; sys...d\"] + sy
s.argv[1:]))" setuptools pip failed with error code 1
C:\>
Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip by default [1], so you may have pip already.
(https://pip.pypa.io/en/latest/installing.html)
So, to install pip, securely download get-pip.py. (https://bootstrap.pypa.io/get-pip.py)
Then run the following (which may require administrator access):
python get-pip.py

Virtualenv returning a 'No such file or directory...' error

The command virtualenv --no-site-packages env/ produces the following error stack trace:
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in env/bin/python
Installing setuptools.............done.
Installing pip...
Error [Errno 2] No such file or directory while executing command /home/zach/School/CS...env/bin/easy_install /usr/local/lib/pytho...pport/pip-1.1.tar.gz
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.7.1.2', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1042, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 640, in install_pip
filter_stdout=_filter_setup)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 966, in call_subprocess
cwd=cwd, env=env)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1239, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I am using Ubuntu 11.10 and Python 2.7.
EDIT:
Figured it out.
I originally installed it with pip, so I uninstalled via pip and that reinstalled via apt-get.
I had the same on debian. Upgrade python-virtualenv resolves the problem.
apt-get upgrade python-virtualenv
virtualenv looks to be trying to install pip using easy_install from a local archive. Can you verify that it exists at /usr/local/lib/pytho...pport/pip-1.1.tar.gz ?
You may want to ensure that you have pip properly install beforehand. Try: easy_install -U pip first.
In mac run pip install virtualenv virtualenvwrapper to install virtualenv.
You should make sure the path to easy_install does not have spaces in it: /home/zach/School/CS...env/bin/easy_install
If you are Debian user, then this command should resolve the problem:
sudo apt-get upgrade python-virtualenv

Categories