Reputation: 1053
Somehow my Python/Conda/Pip installation is such that pip - even when operating within an active conda environment - attempts to install to the global site-packages directory.
On my macbook pro running 10.12.4, I can reproduce by:
$conda create -n test python=3.6
$source activate test
$which pip
/Users/ethankeller/anaconda3/envs/test/bin/pip
$pip install numpy
Collecting numpy
Using cached numpy-1.13.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing collected packages: numpy
Exception:
Traceback (most recent call last):
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/lib/python3.6/site-packages/numpy'
I imagine that some environment variable is set wrong somehow... Any advice on what could be wrong, or where to start looking?
Upvotes: 1
Views: 3493
Reputation: 2253
To install it globally you can use "sudo pip install numpy"
Avoid using sudo to save yourself a lot of trouble down the road. sudo will install the Python packages 'globally' and may overwrite existing installation, cause dependency errors and affect other users. Use virtualenv where possible, otherwise pip install --user, this will install packages in the current user
pip install numpy --user
Upvotes: -3
Reputation: 152
After struggling for a while, I was so willing to make myself clear of this issue, so I searched for a while, and just figured out and tested.
When you create a new conda env by specifying the python version, it will use the conda_root_python version. And if you didn't install the pip package, and try to use pip under your created conda env, it will only run the conda_root_pip and install the package in the root site_packages.
I know three ways to install python packages only in your created conda env. For a better explanation, we create a conda env with same python version of conda root environment.
conda create -n myenv python
I. One of the officials advise, install package with conda command for specified conda environment,
conda install -n myenv tensorflow
II. Another one of official advise, get into your specified environment and run conda install
source activate myenv
conda install tensorflow
in above two ways you don't need to install extra packages like pip and other pip related packages.
III. For people who really want to pip, just because get used of that. install pip package(just as above two ways did).
conda install -n myenv pip
or
source active myenv
conda install pip
then comes the pip install when you are in your environment
pip install tensorflow
Upvotes: 6