How to install Python dependency properly? (maybe without sudo?) - python

I'm trying to run some code with python. It is using tweepy library. Then, I got this error:
Traceback (most recent call last):
File "script.py", line 1, in <module>
import tweepy
ImportError: No module named 'tweepy'
So, I tried to install dependency:
pip install tweepy
And it get permission denied:
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/sockshandler.py'
Consider using the `--user` option or check the permissions.
Next thing to do is to run using sudo. I had a bad experience by using sudo for docker, because it creates protected files all over my local. But I finally tried it anyway sudo pip install tweepy
It returns success, but I still get the same error when I tried to run python3 myscript.py
But, I see some warning to upgrade the pip, so I think maybe that's it. I tried to upgrade pip using both pip install --upgrade pip and sudo pip install --upgrade pip
Still not working.. I tried one last trick up my sleeve. Change the terminal. I think, "maybe after installing, some environment variable not running on this terminal"
Nope. Not working. I admit it should be a newbie question. Having tried some solution on the web, but still not working. Thanks.

If you use python3, you should be using pip3, pip is most likely the python2 pip.
However, better is using python3 -m pip install tweepy that ensures you use the pip for your specific python version.
You can also install it as a user without sudo for just your local account:
python3 -m pip install --user tweepy

Look at the error message:
... Permission denied: '/usr/local/lib/python2.7 ....
You installed tweepy in your python2 Installation.
Use pip3 install tweepy instead. Maybe with sudo when you get the error with permission denied again. After that you can go with
python3 myscript.py

Use the --user flag, like so...
pip|pip3 install <PACKAGE> --user
This will install it in a location available and writeable to your user
See https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

You seems to have 2 python installations on the machine. Python 3.x and Python 2.7.
When you run the pip command , the alias points to pip2 which installs packages for Python 2.7 - which is clear in your error message
Permission denied: '/usr/local/lib/python2.7/dist-packages/sockshandler.py'
So if you want to install packages for python 3, then use the command pip3 instead of pip.
Like sudo pip3 install tweepy
If you want the pip to work as pip3 you can consider adding an alias with alias pip=pip3
You have to make sure the pip is pointing to right python version.

Related

Attempting to upgrade pip from version 20.3.1 to version 21.3. How do I use the `--user` option?

For the sake of experience, I'd prefer to try this in cmd and not use get-pip in pypi.org
Tried changing windows account from user to administrator and a youtube instruction video.
Was awarded the following error message:
Successfully uninstalled pip-20.3.1
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'C:\Users\User\AppData\Local\Temp\pip-uninstall-j78tgiwv\pip.exe'
Consider using the --user option or check the permissions.
Running pip install --upgrade --user pip (like pip is suggesting) will install pip on the user site packages (not the global). This works fine on some cases, but the upgraded package will only be available to the user who installed.
As I can read, your message seems harmless (it failed on a temporary file), if you run pip --version you should see the latest version. However, if that doesn't work, you may have to add the --user option to your command.

How do I fix pip install error even when trying to install from local archive?

I'm getting an SSL error when trying to use pip install openpyxl. This is a work PC and we go through proxy. I have also installed other packages using this method py -m pip install C:\Users\Lamar\Downloads\ <package file name> with a local tar.gz file which worked fine but when trying to use py -m pip install C:\Users\Lamar\Downloads\openpyxl-3.0.7.tar.gz I get the same error even though as if I am using (pip install openpyxl). Before attempting this openpyxl I just installed py -m pip install C:\Users\Lamar\Downloads\xlrd-2.0.1.tar.gz with no problems, could someone explain to me how this is possible and how to correct it. I also have tried the "trusted host" approach but that gives a "Cannot connect to proxy" error.

python pip broken by virtualenv

I recently had to switch my machine at work. On the new machine, pip is not anymore.
$ pip --version
...
OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/virtualenv-15.0.1.dist-info'
I imagine that this issue is caused by virtualenv, as I never encountered any problems on my old machine and the only difference I find, is that there was no virtualenv package installed on the old machine.
However
$ python -c "import pip; print pip.__version__"
10.0.1
still works.
I would be grateful if anyone could provide help, how to fix this problem or trace down the real problem.
Please note: I do not have root rights.
Here the problem is you don't have permission to the system folder. So whenever you use pip try to use it like this.
python -m pip install --user package
Here the package means the package you need to install using pip. Furthermore try using the following command to upgrade the version of your pip.
python -m pip install --user --upgrade pip

Installing Django on Bluehost

I'm wanting to use django on bluehost, and I've gotten as far as installing python 2.7, then running python get-pip.pyto install / update pip. And now hoping to install virtualenv; the instructions say to run sudo pip install virtualenv but neither the sudo or non-sudo version of this command works.
Sudo is flat out not permitted on Bluehost's shared hosting environment, and when I type pip, I get command not found. So I am to assume pip is still not installed, despite the successful execution of
python get-pip.py
When I type which pip I get nothing, while which easy_install
gives me a path.
So is it there? I'm quite confused.
I've been stuck for some time. Help is much appreciated.
The following command works for me when I want to run pip:
python -m pip install <package_name>

Install pip without root but with the system's python

I am trying to install pip without sudo.
Reading the Install Docs, it appears to be possible to use --user to have it being installed in my home directory.
After uninstalling pip from the global scope I tried python get-pip.py --user and obtain the following error:
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/wheel-0.29.0.dist-info'
Checking the Install Docs I found the following notice:
Be cautious if you're using a Python install that's managed by your operating system or another package manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state.
Can I install pip into my home with the casual Ubuntu apt-get python? Or do I also need to build python locally?
As phd mentoined in the comment of my question, cloning pip and installing it via python setup.py install --user worked out fine.

Categories