Cannot pip install anything with OS X El Capitan - python

I am trying to pip install virtualenv (and anything else) on OS X El Capitan and got the following error:
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 311, in run
root=options.root_path,
File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 646, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 339, in move_wheel_files
clobber(source, lib_dir, True)
File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 282, in clobber
ensure_dir(dest) # common for the 'include' path
File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 71, in ensure_dir
os.makedirs(path)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 1] Operation not permitted: '/usr/lib/python2.7/site-packages'
Looks pip is trying to write in '/usr/lib/python2.7/site-packages' and due to SIP in El Capitan it got denied.
But I was wondering why does pip needs to write there? How can I fix this?
I ran brew doctor
which gives
Your system is ready to brew.
So I think it is OK.
I tried brew reinstall python and it gives an odd error:
==> Reinstalling python
Error: /usr/local/opt/python is not a valid keg
which python gives
/usr/local/bin/python
So where in system has this weird thing that let pip fail
Update:
It looks my pip is pointing to system python rather than brewed python.
I changed the first line of pip to
#!/usr/local/bin/python
and problem is solved

You may need to brew link python, or unlink then link to get things pointing to the correct places.

Related

Installing Pandas on MacOs. Permission Error

I am trying to pip install pandas on a mac. I have python 3.6 installed.
When I pip install in the terminal I get the following error:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, 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/pandas'
Could you possibly edit the error into a formatted code block by highlighting it and pushing ctrl+k so it is easier to read? Thanks.
Edit: Also, I just looked through and at the bottom it says permission denied. Try rerunning the command as an admin. I.E try this command:
sudo pip install pandas
You might have already noticed, Mac come with a built in Python, python 2.7. If you read your traceback: /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py it's pointing to the 2.7 dir. this dir is in the Library folder so you don't have permission to install to it.
But you state that you have Python 3.6 installed as well, so if you wanted to install to that indtead. Do pip3 install pandas or python3 -m pip install pandas this help specify the python version. And if you want to run python 3.6 in terminal, type python3 instead of just python

sudo pip install django-nose: "no such file or directory" followed by an empty string?

When trying to sudo pip install django-nose, I get a strange error:
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/commands/install.py", line 347, in run
root=options.root_path,
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_set.py", line 549, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 754, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/req/req_install.py", line 963, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/wheel.py", line 266, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/usr/local/lib/python2.7/site-packages/pip-6.0.8-py2.7.egg/pip/wheel.py", line 176, in clobber
os.makedirs(dest)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 2] No such file or directory: ''
I am only using sudo because without sudo, I get a IOError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/nose/__init__.py'. Here is what I get for which Python and pip is being used, which I think are both what I want them to be:
$ which python
/usr/local/bin/python
$ which pip
/usr/local/bin/pip
This is a separate issue, but I wonder if it's related: I also get this error while trying to create a virtualenv: IOError: [Errno 13] Permission denied: '/lib/python2.7/site-packages/easy_install.py'
I recently upgraded to El Capitan, and it seems like there were some permissions changes that may have caused it to suddenly not work even though it has been working for a while. (Although I'll admit I'm not super experienced here, so I could be doing something very obviously wrong.) I just have no idea how to even decipher this error, and obviously I don't want to do any chmod or chown on system files unless I absolutely know it will solve my problem. Any suggestions would be greatly appreciated!

pip freeze is giving me the global packages

I'm fairly new to python so please bear with me. I installed the virtual env created a new environment and everything very smooth(great). so when I try to pip freeze it gives me all the global packages that are installed and not only the environment im in. Then I try to install django and it does not let me. This is the error that gives me...
→ pip install django
Collecting django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)
100% |████████████████████████████████| 6.6MB 187kB/s
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py", line 209, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_set.py", line 732, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 835, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 1030, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/wheel.py", line 344, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/wheel.py", line 315, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/utils/__init__.py", line 83, 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'
OK. I got it working. The problem was something with a cache directory. When I reinstalled virtualenv I used a flag plus sudo.
sudo pip install --no-cache-dir virtualenv
but new questions comes up.
How important is a cache directory for the environments?
Do I need one yes o no?
Thanks all for your awesome help.

What is the error I am facing when I am installing Django via PIP in a virtualenv?

On my OSX 10.10.2, in a virtualenv, I tried to install Django via pip using the command:
pip install django
And this the responds I got:
Collecting django
Downloading Django-1.7.7-py2.py3-none-any.whl (7.4MB)
100% |################################| 7.4MB 58kB/s
Installing collected packages: django
Exception:
Traceback (most recent call last):
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/basecommand.py", line 232, in main
status = self.run(options, args)
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/commands/install.py", line 347, in run
root=options.root_path,
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/req/req_set.py", line 549, in install
**kwargs
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/req/req_install.py", line 754, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/req/req_install.py", line 963, in move_wheel_files
isolated=self.isolated,
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/wheel.py", line 266, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/site-packages/pip/wheel.py", line 212, in clobber
shutil.copyfile(srcfile, destfile)
File "/Users/qmbp/.virtualenvs/demo/lib/python3.4/shutil.py", line 109, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: '/Users/qmbp/.virtualenvs/demo/bin/django-admin.py'
I guess the issue is caused as I did not prefix sudo to the command. But I read that it was a good idea to use sudo in OSX. And that is why virtualenv is encouraged as sudo is not needed inside it.Here is a screenshot of my files as I could not find the "env" in the bin folder.
Looks like you forgot to activate your venv.
Try:
source path_to_your_venv/bin/activate
pip install django

Issues in Installing Python packages in webfaction

I am trying to install packages using PIP but it doesn't work for me initially it gives the permission denied error and after that when I tried to use easy_install it gives me this error :->
Searching for mezzanine
Reading https://pypi.python.org/simple/mezzanine/
Reading http://github.com/stephenmcd/mezzanine/
Reading http://mezzanine.jupo.org/
Best match: Mezzanine 3.1.8
Downloading https://pypi.python.org/packages/source/M/Mezzanine/Mezzanine-3.1.8.tar.gz#md5=dcc46016b866ea8de1c87fb9dffd9163
Processing Mezzanine-3.1.8.tar.gz
Writing /tmp/easy_install-2cSSS_/Mezzanine-3.1.8/setup.cfg
Running Mezzanine-3.1.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-2cSSS_/Mezzanine-3.1.8/egg-dist-tmp-uDjreS
Traceback (most recent call last):
File "/usr/local/bin/easy_install", line 8, in ?
sys.exit(
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1924, in main
with_ei_usage(lambda:
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1911, in with_ei_usage
return f()
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1928, in <lambda>
distclass=DistributionWithoutHelpCommands, **kw
File "/usr/local/lib/python2.4/distutils/core.py", line 149, in setup
dist.run_commands()
File "/usr/local/lib/python2.4/distutils/dist.py", line 946, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python2.4/distutils/dist.py", line 966, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 374, in run
self.easy_install(spec, not self.no_deps)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 609, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 639, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 825, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1031, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/usr/local/lib/python2.4/site-packages/setuptools/command/easy_install.py", line 1016, in run_setup
run_setup(setup_script, args)
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 68, in run_setup
DirectorySandbox(setup_dir).run(
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 120, in run
return func()
File "/usr/local/lib/python2.4/site-packages/setuptools/sandbox.py", line 71, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 22
with open(e, "r") as f:
^
SyntaxError: invalid syntax
After this when I again try to use pip then I am getting different error (not permission denied) :
File "/home/rishi/bin/pip", line 8, in ?
sys.exit(
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 357, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2394, in load_entry_point
return ep.load()
File "/usr/local/lib/python2.4/site-packages/pkg_resources.py", line 2108, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/rishi/lib/python2.4/pip-1.5.6-py2.4.egg/pip/__init__.py", line 9, in ?
from pip.log import logger
File "/home/rishi/lib/python2.4/pip-1.5.6-py2.4.egg/pip/log.py", line 19
real_consumer = (consumer if not isinstance(consumer, colorama.AnsiToWin32)
^
SyntaxError: invalid syntax
Now I don't know what I am doing wrong , can anybody help me ?
EDIT :- syntex errro solved due to wrong python version , I was using 2.4 .
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/site-packages/mezzanine'
$which pip result is
~/bin/pip
Just add the --user option to your pip command, it will install with your logged in user permissions:
pip2.7 install mezzanine --user
as Daniel Roseman noted - the syntax error came from using Python2.4
the permission problem is caused by trying to install into system Python, what requires sudo or being root
Possible solutions
Install into system Pyhton (using sudo)
$ sudo pip install mezzanine
This will spoil the system Python and is not much recommended. It would be well acceptable if you are e.g. under Docker.
Install into user profile
$ pip install --user mezzanine
It will install the package into user scheme and will not spoil system Python.
This is more acceptable, but can soon become messy environment to run code in, as Python will import form user scheme, sometime from system.
Use virtualenv
Assuming you have virtualenv installed:
$ cd ~/projects
$ mkdir mezza
$ cd mezza
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install mezzanine
$ pip freeze
mezzanine==3.1.8
(there will be a bit more lines from freeze).
This installs into virtualenv, which is easy to recreate, destroy, and does not mess up with other environments.
With virtulanevwrapper you will get set of additional tools, which will simplify your environment a lot.

Categories

Resources