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.
Related
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....
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 django using pip in Terminal.
I always get an exception, however. The last error is always "permission denied", and I do not understand why. Any help is appreciated.
Log:
pip install django
You are using pip version 7.1.0, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django
Using cached Django-1.9.4-py2.py3-none-any.whl
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 299, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 646, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 813, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 1008, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 339, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 310, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 70, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'
sudo pip install django
The error tells you that you can't access a directory (you don't have enough permissions), so you can gain root access via sudo to get the permissions.
pip should be run by a user which has permissions to write to site-packages directory (in your case, /Library/Python/2.7/site-packages/). You should either run it from the root user or under sudo.
My Solution for [Errno 13] Permission denied:
Target: To install package into system/virtualenv
Why you get this problem?
Because apart from root, other users you created don't have permission to write to site-packages, that is why you get OS error permission denied for that user
How to solve?
Make sure you activated the virtualenv all the time
Source bin/activate
Suppose, I created a user
(sampleEnv) sunny#ubuntu-512mb-lon1-01: pip install django
This will give the Permission error, Instead of that shift to root
$ su -
(sampleEnv) root#ubuntu-512mb-lon1-01: pip install django
Now root have permission to write to site-packages.
Once django is installed. Shift back to user
$ su - sunny
then do pip freeze you can see packages installed in system and go on!
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'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...