In my MacOS Mojave terminal I wanted to install a python package with pip. At the end it says:
You are using pip version 10.0.1, however version 18.1 is avai
For MacOs & Unix
Just by adding sudo to command will work, as it would run it as a superuser.
sudo pip install --upgrade pip
It is advised that you should not directly do it though - please see this post
I have anaconda installed for Python 3. I also have Python2 in my mac.
python --version
gives me
Python 3.7.3
python2.7 --version
gives me
Python 2.7.10
I wanted to install pyspark package in python2, given that it was already installed in python3.
python2.7 -m pip install pyspark
gives me an error
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pyspark' Consider using the
--user
option or check the permissions.
The below command solved it. Thank god I didn't have to do any config changes.
python2.7 -m pip install pyspark --user
Collecting pyspark Requirement already satisfied: py4j==0.10.7 in /Library/Python/2.7/site-packages (from pyspark) (0.10.7) Installing collected packages: pyspark Successfully installed pyspark-2.4.4 You are using pip version 18.1, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.
If you want to use python3+ to install the packages you need to use pip3 install package_name
And to solve the errno 13 you have to add --user
at the end
pip3 install package_name --user
EDIT:
For any project in python it's highly recommended to work on a Virtual enviroment, is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.
In order to create one with python3+ you have to use the following command:
virtualenv enviroment_name -p python3
And then you work on it just by activating it:
source enviroment_name/bin/activate
Once the virtual environment is activated, the name of your virtual environment will appear on left side of terminal. This will let you know that the virtual environment is currently active.
Now you can install dependencies related to the project in this virtual environment by just using pip
.
pip install package_name
I got the same error when I was trying to install a package (flask-classful).
I made the mistake of installing anaconda as root. I changed the ownership of the installed anaconda folder and I could install the package successfully.
Use the command chown
with option -R
to recursively change ownership of the installed anaconda folder like so:
chown -R owner:group /path/to/anaconda
Here owner is your username and group is the group name.