Permission error with pip Python 3 - python

I am using Python 3 on Mac OS X. Everything was perfect, I used to install packages like this:
pip install somePackage
But IDLE stopped working so I had to re-install it. After that, when I ran pip, I got pip is not defined so I had to install pip. Now, every time I try to install a package using pip, I get this 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 377, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 287, in clobber
ensure_dir(dest) # common for the 'include' path
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 1] Operation not permitted: '/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pygame'
I thought it may be from the version so I updated it. Now, whenever I run pip install something I get this error:
Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/private/var/folders/bc/hwpn9sqn5352xcbst0p89snm0000gn/T/pip-build-hSNyxK/termcolor/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /var/folders/bc/hwpn9sqn5352xcbst0p89snm0000gn/T/pip-U3ZtNq-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/bc/hwpn9sqn5352xcbst0p89snm0000gn/T/pip-build-hSNyxK/termcolor/
I can't even delete a package - when I run pip uninstall something I get this 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/uninstall.py", line 76, in run
requirement_set.uninstall(auto_confirm=options.yes)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 346, in uninstall
req.uninstall(auto_confirm=auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/var/folders/bc/hwpn9sqn5352xcbst0p89snm0000gn/T/pip-OQKY_a-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy-1.8.0rc1-py2.7.egg-info'
My pip version is :
pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
I am using Mac 10.12.6
How can I fix this?

The permission error you're seeing is due to the fact that your site-packages directory (where pip is trying to install to) is protected and owned by an administrator.
Where is the site packages directory
It depends on your Python distribution. That's why I asked for you to include the output of the $ which python command (from the command line), and the >>> import site; site.getsitepackages() command (from Python). These will help you figure out where your site packages directory is. Also, running pip -v will print the directory to which pip is trying to install.
It is important to note that Macs come with a system version of Python. You should not install any packages accessible to this system version of Python, because it is used by the system and you can potentially interfere with its normal workings and/or install malicious versions of packages that will do bad things when the system uses that Python (e.g., if someone made a nasty egg and called it "os" and put it in the site-packages directory for your system Python, then the next time the system python version ran "import os" it would import the nasty egg.)
Why overriding with sudo pip install is not a good solution
While running your pip install command as sudo would probably solve the problem, this is a short-term fix that is very bad for the reasons mentioned in my comment in #Nenand's answer - running pip install X downloads the egg for X from the internet, and runs python setup.py build && python setup.py install on whatever happens to be in the setup.py. While it's easy to be lulled into complacency because, hey, it works!, it's also naive to trust strangers on the internet (and let's face it, the people who make pip packages are strangers to you).
EDIT: I didn't even think of this, but there is also the potential that you mis-type a library, or guess the wrong name, and end up with one you REALLY didn't want (typosquatting). See this BleepingComputer article on typosquatting pip packages.
The proper solution
The proper solution is to figure out why your site-packages directory is protected, and either fix its permissions, or change the site-packages directory pip is using.
I suspect the reason you're seeing this permissions error is that pip is trying to install to the system Python's site-packages directory, which is owned by root for a good reason. The system Python is located at /usr/bin/ and its site-packages directory is located at the following directories:
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages'
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/site-python'
'/Library/Python/2.7/site-packages'
My advice, in this case, is to install Python using Homebrew, Python.org, or Canopy, which will keep your snakes in separate cages and will leave the system Python alone. On my system, python is the system python, python2 is Python version 2, and python3 is Python version 3. This also makes it more clear which version I'm using. I also do not have a pip command - not on my path - so I can't accidentally install something to my system Python. I have to explicitly call pip2 or pip3. Using Homebrew Python will do all of this for you, so that's my most-favored recommendation of the many Python distributions available.

Related

Why does Pip disregard configured repository with nested dependencies?

Problem
Let us say I have a completely empty Python+Pip+R (pip 19.3.1) environment on a Linux machine and I want to install the package rpy2 with pip. Since I am behind a corporate firewall I configure pip to use a private repository.
[global]
index-url = http://private.com/artifactory/api/pypi/PyPI/simple
trusted-host = private.com
Now I execute pip install rpy2 and I will get back the following error:
Couldn't find index page for 'cffi'
Download error on https://pypi.python.org/simple/
So pip tries to resolve the nested dependency by looking and installing cffi from the official PyPi repository. It completely ignores the repo I have configured.
When I run pip install cffi && pip install rpy2 one after another everything works as expected.
Here is the full error output:
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-8vuadu93/rpy2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-8vuadu93/rpy2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-8vuadu93/rpy2/pip-egg-info
cwd: /tmp/pip-install-8vuadu93/rpy2/
Complete output (25 lines):
Download error on https://pypi.python.org/simple/cffi/: [Errno -2] Name or service not known -- Some packages may not be found!
Couldn't find index page for 'cffi' (maybe misspelled?)
Download error on https://pypi.python.org/simple/: [Errno -2] Name or service not known -- Some packages may not be found!
No local packages or working download links found for cffi>=1.13.1
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-8vuadu93/rpy2/setup.py", line 183, in <module>
'rinterface_lib/R_API_eventloop.h']}
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 128, in setup
_install_setup_requires(attrs)
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 123, in _install_setup_requires
dist.fetch_build_eggs(dist.setup_requires)
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 513, in fetch_build_eggs
replace_conflicting=True,
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 774, in resolve
replace_conflicting=replace_conflicting
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1057, in best_match
return self.obtain(req, installer)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1069, in obtain
return installer(requirement)
File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 580, in fetch_build_egg
return cmd.easy_install(req)
File "/usr/lib/python3/dist-packages/setuptools/command/easy_install.py", line 692, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('cffi>=1.13.1')
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Question
Is this a bug in Pip, a specific problem with rpy2 or am I missing something?
Updates
Running the following commands gives me the same error:
pip install rpy2 --no-index --find-links http://private.com/artifactory/api/pypi/PyPI/simple
pip install rpy2 --index-url http://private.com/artifactory/api/pypi/PyPI/simple
I used -vvv and it seems like the problem occurs somewhere inside of setuptools
Solution
The package rpy2 uses setuptools which again uses easy_install.py. It also works with an index_url variable. But it gets the value not from pip.config but distutils.cfg.
I identified all Python versions I have installed with find / -name "distutils". Then I added the a distutils.cfg with the following content to each of these directories:
[easy_install]
index_url = blablabla
And now it works, I execute pip install rpy2 and all missing requirements are installed in one go
I believe it could be caused by the fact that cffi is listed as setup_requires in rpy2's setup.py. Most likely because cffi is required to build the project itself before it can be installed. This kind of build dependencies are not handled by pip directly, so its index-url option has no effect.
The solution is to tell setuptools about the alternative index in a distutils configuration file
[easy_install]
index_url = https://my.index-mirror.com
References:
"Controlling setup_requires" in pip's documentation
setuptools, easy_install, and a custom pypi server
distutils configuration file

Installing error with six dependency

Running setup.py install for anyjson ... done
Found existing installation: six 1.4.1
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.4.1:
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install
requirement.uninstall(auto_confirm=True)
File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall
paths_to_remove.remove(auto_confirm)
File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove
renames(path, new_path)
File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames
shutil.move(old, new)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move
copy2(src, real_dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 1] Operation not permitted: '/tmp/pip-29Cml5-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'
Snippet of error stacktrace.
While running requirements.txt on python.
Is it due to six.
Ignoring it does NOT help.
sudo -H pip install -r requirements.txt --ignore-installed six
Double requirement given: six==1.10.0 (from -r requirements.txt (line 107)) (already in six, name='six')
This post does not help - https://github.com/pypa/pip/issues/3165
Sometimes, the Extras problem I'm going to describe does not affect venvs. Sometimes it does, but if using virtualenv is at all an option, you should try that before doing anything else.
So, let's assume you either can't do that, or you tried it and this is one of the cases where it doesn't actually help.
First, let me say that all of the following is terrible, terrible advice for any purpose except installing new versions of packages that Apple pre-installed in Extras with Apple's Python 2.7 in OS X 10.7-10.13. Anyone reading this who does not have exactly that problem, stop reading now.
Apple's system version of Python 2.7 comes with a nifty set of third-party packages preinstalled in:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/
Rather than try to keep these packages up to date, they designed things so that you can easily shadow them with a newer version in your site-packages directory. Which wasn't a terrible idea.
Unfortunately, they stopped doing any serious maintenance on this a few versions of OS X back, but didn't stop shipping it. In particular, they never updated it to work with setuptools and pip, and if you install pip properly (using the get-pip.py script instead of easy_install), shadowing installs will basically never work.
If your pre-installed easy_install is still working, it should still work to install shadowing packages. Do not use it for anything else, but for this specific purpose, it's the right tool. But it doesn't work for every package on every OS X version, so it's a bit of trial and error. You may want to back up Extras and site-packages first just in case.
The way to test it (assuming easy_install succeeds, of course—if it fails with a slew of errors, it obviously didn't work… and it's time to restore your backups) is to start Python, import six, and look at six.__version__ or six.__file__. If it's the new version in site-packages, you win.
If that doesn't work, there's a hacky workaround that may solve your problem: Temporarily move the file Extras/lib/python/six-1.4.1-py2.7.egg-info somewhere else, then see if pip install six successfully installs into your normal site-packages. If so, restore the egg-info file, and test the shadowing again.
If that still didn't work… well, you can install manually, but I think at this point, the pain of having two Python 2.7 installations in parallel is less than the pain of managing the one you have, so I'd consider installing another one (python.org, Anaconda, or Homebrew) and being careful to never touch the Apple one again (virtualenv can help with this).

pip uninstall working but giving error

I have downloaded, built and installed the sample pypi project. The project is supposed to be used to give an insight to python packaging and is referenced in Python Packaging User Guide and Packaging and Distributing Projects. I am therefore confused to why on earth following their instructions on creating the package I have an error when uninstalling it.
As mentioned above I have used their sample project. If anyone can shed some light it would be appreciated.
Key notes: I am running Mac OSX, my installed python version is 3.5.1
Below are steps to reproduce the problem:
mkdir testdirectory
cd testdirectory/
pyvenv venv # Creating a virtual environment
source venv/bin/activate
git clone https://github.com/pypa/sampleproject.git # Getting sample project
cd sampleproject/
python setup.py build
python setup.py install # Installing on the virtual environment
pip list
peppercorn (0.5)
pip (7.1.2)
sample (1.2.0)
setuptools (18.2)
pip uninstall sample
Resulting in the following output:
Uninstalling sample-1.2.0:
/Users/steve/testdirectory/venv/bin/sample
/Users/steve/testdirectory/venv/lib/python3.5/site-packages/sample-1.2.0-py3.5.egg
Proceed (y/n)? y
Successfully uninstalled sample-1.2.0
Traceback (most recent call last):
File "/Users/steve/testdirectory/venv/bin/pip3", line 11, in <module>
sys.exit(main())
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/__init__.py", line 217, in main
return command.main(cmd_args)
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/basecommand.py", line 248, in main
pip_version_check(session)
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/utils/outdated.py", line 102, in pip_version_check
installed_version = get_installed_version("pip")
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/utils/__init__.py", line 858, in get_installed_version
working_set = pkg_resources.WorkingSet()
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 629, in __init__
self.add_entry(entry)
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 685, in add_entry
for dist in find_distributions(entry, True):
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2075, in find_eggs_in_zip
if metadata.has_metadata('PKG-INFO'):
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1605, in has_metadata
return self.egg_info and self._has(self._fn(self.egg_info, name))
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1963, in _has
return zip_path in self.zipinfo or zip_path in self._index()
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1843, in zipinfo
return self._zip_manifests.load(self.loader.archive)
File "/Users/steve/testdirectory/venv/lib/python3.5/site-packages/pip/_vendor/pkg_resources/__init__.py", line 1783, in load
mtime = os.stat(path).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/Users/steve/testdirectory/venv/lib/python3.5/site-packages/sample-1.2.0-py3.5.egg'
It appears that the package has uninstalled correctly however the error is still thrown.
This is documented:
$ pip help uninstall
Usage:
pip uninstall [options] <package> ...
pip uninstall [options] -r <requirements file> ...
Description:
Uninstall packages.
pip is able to uninstall most installed packages. Known exceptions are:
- Pure distutils packages installed with ``python setup.py install``, which
leave behind no metadata to determine what files were installed.
- Script wrappers installed by ``python setup.py develop``.
i.e. you are getting the error because you didn't use pip itself to install - you used setup.py and so pip doesn't know what was installed.
Install package not with python setup.py install but with pip install .
Then uninstalling will work without errors

Python pip broken - installing Pelican

I'm trying to install Pelican for python using pip install pelican, but I get these errors. I use Python 2.7.9 bundled with Mac OSX
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg >/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg
/pip/commands /install.py", line 311, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req
/req_set.py", line 646, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req
/req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/req
/req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-7.1.2-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.2-py2.7.egg/pip/wheel.py", >line 310, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-7.1.2-py2.7.egg/pip/utils
/__init__.py", line 71, 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/pelican'
Evens-MacBook-Pro:~ even$
Your normal user cannot install to the system-wide Python package directory. Instead of using sudo, install the package locally for your user account:
pip install --user pelican
That error occured because you don't have permission to write on that system directory. Hence the OSError: [Errno 13] Permission denied.
If you want to install it system wide, you have to run pip with superuser rights in order to gain permission:
sudo pip install pelican
Although, that wouldn't be necessary -- nor a good practice --, for instance, if you are installing inside a virtualenv.
Another possibility, as referred in this answer pointed out by #pherris, is to append the --user flag to the pip command. This would install the package only to the current user:
pip install pelican --user
Modifying the system-level installation of Python (or Ruby, or Perl...) can turn into a mess, and I have had my work there trashed in the past by system updates. Apple doesn't really guarantee your local changes will be preserved after an OS update.
You are likely better off installing your own versions using something like Homebrew, which installs into /usr/local.
Homebrew has Python 2.x and 3.x available (and they can co-exist very well). It keeps up with new releases better than Apple does. Homebrew also has many other Unix things that you may or may not find useful.
After installing Homebrew, installing Python is simple:
brew install python
brew install python3
Make sure /usr/local/bin is early in your $PATH. It also provides you with pip and pip3 to install Python package for both 2.x and 3.x.

Exception Error when Installing NumPy with pip

I have been trying to install NumPy and have been have a brutal time with it. I keep getting an exception error no matter what I try. I used the command
$pip install numpy
but it threw this error
Exception:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/basecommand.py", line 246, in main
status = self.run(options, args)
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/commands/install.py", line 352, in run
root=options.root_path,
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/req/req_set.py", line 693, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/req/req_install.py", line 817, in install
self.move_wheel_files(self.source_dir, root=root)
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/req/req_install.py", line 1018, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/wheel.py", line 269, in move_wheel_files
clobber(source, dest, False, fixer=fixer, filter=filter)
File "/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg/pip/wheel.py", line 215, in clobber
shutil.copyfile(srcfile, destfile)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/local/man/man1/nosetests.1'
Just to check, I used import in Python to see if it got anything, it also threw an error though. I have no idea what is going on.
$pip install scipy
gave me no problems. Any help is appreciated! I can't seem to find anything on how to fix this.
Thanks!
Homebrew tries to leave /usr/local writable, so you don't need sudo. See the FAQ for details.
However, if you accidentally use sudo once—or if some other installer you run installs stuff into /usr/local that doesn't realize you wanted it Homebrew-style—then you'll start getting errors, when your Homebrew stuff attempt to modify files that were saved with sudo.
There's a particular problem if you try to use both Apple's pre-installed Python 2.7 and a Homebrew Python 2.7: they both want to install scripts to /usr/local/bin, man pages to /usr/local/man, etc. And Apple's wants to use sudo.
So, most likely, you did a sudo pip install nose for Apple's Python in the past, and now pip install nose for Homebrew's Python is trying to overwrite its files and doesn't have permissions to do so. (Or maybe not nose itself, but something else that requires nose without you realizing it.)
Using sudo with the Homebrew Python will just make the problem worse; don't do that.
The right solution is to either:
Not use a third-party Python 2.7, Homebrew or otherwise, and just stick with Apple's (or upgrade to Python 3; then there's usually no conflict with Apple's 2.7…), or
Never touch Apple's Python 2.7, and only use the other one.
But at this point, you've already screwed things up, and I doubt you want to reinstall your OS from scratch, right?
You can fix things by brew uninstall python for the former, or by uninstalling everything you installed with Apple's Python for the latter. (You can't uninstall Apple's Python; that would break the OS, and the next OS update would just undo it anyway…) And then, either way, you'll probably want to reinstall every package you need for whichever Python you chose to go with, to be safe.
Or, for a quick&dirty solution, every time you get an error like this, you can either delete the conflicting file (sudo rm /usr/local/man/man1/nosetests.1) or make it overwritable (sudo chmod a+w /usr/local/man/man1/nosetests.1); then, your pip will work. Until the next error, which you can fix the same way.
Just run cmd as Admin it worked for me.

Categories