I am unable to create virtual environment using both Python 2.x or Python 3.x. When I try create virtual environment I get error:
$ virtualenv my_env2 [0:05:17] ⚡[..........]
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/user/my_env2/bin/python2
Not overwriting existing python script /home/user/my_env2/bin/python (you must use /home/user/my_env2/bin/python2)
Installing setuptools, pkg_resources, pip, wheel...
Complete output from command /home/lynx/my_env2/bin/python2 - setuptools pkg_resources pip wheel:
Traceback (most recent call last):
File "<stdin>", line 7, in <module>
File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/__init__.py", line 31, in <module>
File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/vcs/mercurial.py", line 9, in <module>
File "/usr/share/python-wheels/pip-9.0.1-py2.py3-none-any.whl/pip/download.py", line 40, in <module>
ImportError: cannot import name requests
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 2375, in <module>
main()
File "/usr/lib/python3/dist-packages/virtualenv.py", line 724, in main
symlink=options.symlink)
File "/usr/lib/python3/dist-packages/virtualenv.py", line 992, in create_environment
download=download,
File "/usr/lib/python3/dist-packages/virtualenv.py", line 922, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/usr/lib/python3/dist-packages/virtualenv.py", line 817, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/user/my_env2/bin/python2 - setuptools pkg_resources pip wheel failed with error code 1
The same error occurs for Python 3.x. Can you help me?
I had a similar problem when trying to do this with Python3. Try this command:
sudo python3 -m <your virtual env name>
First, make a directory of any name :
mkdir testing
Then, moved to this newly created directory named testing :
cd testing
When you type following command in this directory:
python3 -m venv env
You got error like :
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.8-venv
Type the following command but before that keep an eye on the version of python you installed on the machine; in my case its python3.8
sudo apt install python3.8-venv
Now, we can create a virtual environment and store its tools in the "bhandari" folder .
python3 -m venv bhandari
Note: you can named this "bhandari" folder; anyname you like( Standard practice is to name it "env" ...)
Now to activate your virtual environment, from the directory of your folder, type the following command this will activate our virtual environment in the “bhandari” folder
source bhandari/bin/activate
If you have successfully activated your virtual environment, you should see the (bhandari) word indicating that we are working in a virtual environment.
After this, we can install anything that will be isolated from the rest of the system....
Related
I'm unable to install pip using python setup.py --user, and I think my python install is generally a bit foobared.
I want to be able to use pip without sudo on my user (vagrant in this case). Everything I've read indicates that the above should work, but it just refuses to.
If I use sudo python setup.py --user then it installs correctly, but again, the sudo shouldn't be necessary because of the installation to the user directory.
python setup.py --user
Traceback (most recent call last):
File "setup.py", line 6, in <module>
from setuptools import find_packages, setup
File "/home/vagrant/.local/lib/python3.6/site-packages/setuptools/__init__.py", line 16, in <module>
import setuptools.version
File "/home/vagrant/.local/lib/python3.6/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3126, in <module>
#_call_aside
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3110, in _call_aside
f(*args, **kwargs)
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3139, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 572, in _build_master
ws = cls()
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 565, in __init__
self.add_entry(entry)
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 621, in add_entry
for dist in find_distributions(entry, True):
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1968, in find_on_path
for dist in factory(fullpath):
File "/home/vagrant/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2030, in distributions_from_metadata
if len(os.listdir(path)) == 0:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.6/dist-packages/websocket_client-0.54.0.dist-info'
Other bits of info...
python -V
Python 3.6.7
which python
/usr/bin/python
Also, I know that I can use a venv to achieve what I want, but the point is it should work, and doesn't, which a) bugs me to no end, and b) indicates that something is just plain wrong with my setup.
It looks to me as if you are trying to install stuff to the system Python using a non root user and hence do not have permissions to edit stuff in the system's site-packages. Please can you run a whoami and see which user you are logged in as, if you are logged in as someone other than root you should use sudo to install packages into the system's Python, e.g. sudo pip install my_package.
If you do not want to install packages to the system's Python site-packages directory then you probably should be operating in a virtualenv, this gives you a self contained Python env for your project and can be created as any user in their home directory.
To get virtualenv installed:
sudo pip install virtualenv
Then to create a new virtualenv as the user:
virtualenv my_env
Assume / Activate the virtualenv:
source my_env/bin/activate
Now you can install packages using pip as your user into your Python virtualenv:
pip install my_package
This gives you a fully separate Python env running as your user from the system Python installation. Hopefully this helps you, if I have misunderstood your use case please leave a comment and I'll update my answer accordingly.
My system is centos (linux). I have two Python versions, one is 2.7, the other is 3.6. I executed:
$ wget"https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz#md5=834b2904f92d46aaa333267fb1c922bb"# tar -xzvf pip-1.5.4.tar.gz
$ cd pip-1.5.4
$ python setup.py install
But, when I tried to use pip, I got an error:
File "/root/anaconda3/bin/pip", line 11, in <module>
load_entry_point('pip==1.5.4', 'console_scripts', 'pip')()
File "/root/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 565, in load_entry_point
File "/root/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2598, in load_entry_point
File "/root/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2258, in load
File "/root/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg/pkg_resources/__init__.py", line 2264, in resolve
File "/root/anaconda3/lib/python3.6/site-packages/pip-1.5.4-py3.6.egg/pip/__init__.py", line 9, in <module>
from pip.log import logger
File "/root/anaconda3/lib/python3.6/site-packages/pip-1.5.4-py3.6.egg/pip/log.py", line 9, in <module>
from pip._vendor import colorama, pkg_resources
File "/root/anaconda3/lib/python3.6/site-packages/pip-1.5.4-py3.6.egg/pip/_vendor/pkg_resources.py", line 1423, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
What can I do?
Use a virtualenv for specifying the version of python.
Virtualenvs help in solving library conflicts and it is good practice to use a different virtualEnv for every project.
Install virtualenv and virtualenvwrapper
pip install virtualenv
pip install virtualenvwrapper
Add to .zshrc or .bashrc:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/code
source /usr/local/bin/virtualenvwrapper.sh
Specify which Python to use with mkvirtualenv:
virtualenvwrapper lets you specify the python executable without the path:
mkvirtualenv -python=python3 myVirtualEnv
Run: workon
A list of environments, empty, is printed.
Run mkvirtualenv to create a new virtualenv: mkvirtualenv temp
A new environment, temp is created and activated.
Run: workon
This time, the temp environment is included.
workon temp to work on the new virtualenv
use pip to install packages inside the virtualenv
After you're done using the virtualenv, simply deactivate out of it
(if you want to delete the virtualenv, use rmvirtualenv)
Use lssitepackages to list site-packages within the virtualenv.
I'm trying to install the pyv8 package on a virtualenv on Windows.
Here is what I did:
virtualenv venv
venv\Scripts\activate
pip install pyv8
and the last command failed with the following error:
File "<string>", line 17, in <module>
File "<proj_path>\venv\build\pyv8\setup.py", line 17, in <module>
include_dirs += os.environ["INCLUDE"].split(';')
File "<proj_path>\venv\lib\os.py", line 423, in __getitem__
return self.data[key.upper()]
KeyError: 'INCLUDE'
What am I missing?
There is actually an executable that installs it for you on windows.
When you install it, be sure to point the installation directory to your virtualenv directory. You might also want to check out this repeat
I can't create a new virtual environment because of the following error:
$ virtualenv env
New python executable in env/bin/python
Installing distribute....done.
Complete output from command /var/www/vhosts/example.com/...ython /var/www/vhosts/example.com/...stall /usr/lib/pymodules/python2.6/v...ar.gz:
error: Not a URL, existing file, or requirement spec: '/usr/lib/pymodules/python2.6/virtualenv_support/pip-0.6.3.tar.gz'
----------------------------------------
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.4.5', 'console_scripts', 'virtualenv')()
File "/usr/lib/pymodules/python2.6/virtualenv.py", line 537, in main
use_setuptools=options.use_setuptools)
File "/usr/lib/pymodules/python2.6/virtualenv.py", line 630, in create_environment
install_pip(py_executable)
File "/usr/lib/pymodules/python2.6/virtualenv.py", line 390, in install_pip
filter_stdout=_filter_setup)
File "/usr/lib/pymodules/python2.6/virtualenv.py", line 598, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /var/www/vhosts/example.com/...ython /var/www/vhosts/example.com/...stall /usr/lib/pymodules/python2.6/v...ar.gz failed with error code 1
I have already searched the web but couldn't find any solution to this problem. I'm using Ubuntu 10.04.4 LTS with Python 2.6.5 and Virtualenv 1.7.2, any help appreciated. :)
I just figured it out myself: I tried to install virtualenv with apt-get install python-virtualenv.
Executing apt-get purge python-virtualenv && easy_install virtualenv solved the problem.
I'm seeing the same issue, and I did install "python-virtualenv" via "easy_install" instead of "apt-get".
I'm trying to create an environment using virtualenv.
virtualenv test
New python executable in test/bin/python
Error [Errno 2] No such file or directory while executing command install_name_tool -change /System/Library/Fram.../Versions/2.6/Python #executable_path/../.Python test/bin/python
Could not call install_name_tool -- you must have Apple's development tools installed
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 8, in <module>
load_entry_point('virtualenv==1.6.4', 'console_scripts', 'virtualenv')()
File "/Library/Python/2.6/site-packages/virtualenv-1.6.4-py2.6.egg/virtualenv.py", line 810, in main
never_download=options.never_download)
File "/Library/Python/2.6/site-packages/virtualenv-1.6.4-py2.6.egg/virtualenv.py", line 901, in create_environment
site_packages=site_packages, clear=clear))
File "/Library/Python/2.6/site-packages/virtualenv-1.6.4-py2.6.egg/virtualenv.py", line 1166, in install_python
py_executable])
File "/Library/Python/2.6/site-packages/virtualenv-1.6.4-py2.6.egg/virtualenv.py", line 843, in call_subprocess
cwd=cwd, env=env)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 595, in __init__
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/subprocess.py", line 1106, in _execute_child
OSError: [Errno 2] No such file or directory
Folder is created alright, but files like activate are missing. Anyone? (I have xcode 3.2.3 installed. running python 2.6, osx 10.6.8)
Your developer tools are not installed correctly. I recommend installing Xcode 4.
I had the same error messages trying to run virtualenv on a up-to-date Max OS X Lion (10.7.2) installation with XCode installed and very up-to-date using the App Store.
I missed the /usr/bin/install_name_tool as well, however it is there in the system. Use the terminal in the following code blocks.
$ locate install_name_tool
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/install_name_tool
/Developer/usr/bin/install_name_tool
/Developer/usr/share/man/man1/install_name_tool.1
I made a simlink from the /Developer/usr/bin to the /usr/bin with
$ sudo ln -s /Developer/usr/bin/install_name_tool /usr/bin/install_name_tool
Entering the 'which' command yields:
$ which install_name_tool
/usr/bin/install_name_tool
After that I did the virtualenv magic
$ virtualenv -p python2.6 myvirtenv
Running virtualenv with interpreter /opt/local/bin/python2.6
New python executable in myvirtenv/bin/python
Installing setuptools............................done.
Installing pip...............done.
Works like a charm now!
Use install_name_tool from #gregglind's fork of virtualenv:
git clone https://github.com/gregglind/virtualenv.git
cd virtualenv
git checkout feature/install_name_tool
sudo python setup.py install
Credits: macdhuibh (https://github.com/pypa/virtualenv/issues/7)
Get the XCode Command line tools from here:
https://developer.apple.com/downloads/index.action?name=for%20Xcode%20-#
I just fresh installed Lion, and installed XCode from the App Store - and these didn't get installed at the same time, need a separate install now I guess...