Pip: adding directory to PATH - python

I am completely overwhelmed with installing Python3 and Pip.
After running brew install Python3 it seems like Python3 was successfully installed.
Now I tried to run Scrapy again but this error occurs:
-bash: /usr/local/bin/scrapy: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
I guess because the Python version changed?
So I tried to uninstall Scrapy which needs pip.
Here comes the next issue - after installing pip like explained here (https://pip.pypa.io/en/stable/installing/#install-pip) I see this error:
Clms:~ userName$ python3 -m pip install -U --force-reinstall pip
Collecting pip
Using cached pip-20.0.2-py2.py3-none-any.whl (1.4 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Uninstalling pip-20.0.2:
Successfully uninstalled pip-20.0.2
WARNING: The scripts pip, pip3 and pip3.7 are installed in '/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-20.0.2
I truly have no idea how to fix that mess.
Googled for hours, tried a lot but could not figure out to resolve this situation.
Most explanations I encounter require more knowledge about this topic and one leads to the other.
I would be highly grateful for a rescue!
Thanks!

First, you're running the program with python 2.7 not with python 3.x
To run the python on python 3.x use
python3 program.py
Second, regarding the warning. It means the path of the pip is not added to the environment variable PATH. Means you can't call pip from any location, you need to go to its root path to call pip.
Run the below command to update the environment variable PATH to include the root path of pip.
export PATH=/usr/local/Cellar/python/3.7.6_1/Frameworks/Python.framework/Versions/3.7/bin:$PATH
This change is temporary. Depends on your OS, different process you need to follow to permanently update environment variable PATH

Related

Error : No module named 'psutil'

I've been trying to install Peter Chervenski's MultiNEAT and ran into a problem while running setup.py (python setup.py build_ext):
File "c:/Users/1234/Documents/Alex/multineat/peter-ch-MultiNEAT-f631e2f/setup.py", line 7, in
from site-packages import psutil'
And I made sure this module is installed: used pip install a couple of times and it said:
Requirement already satisfied: psutil in
c:\users\1234\appdata\local\programs\python\python36-32\lib\site-packages
And I checked this directory myself and found psutil module there (I even deleted it and reinstalled one more time). And after that, I still got the same error with Python not seeing psutil. Is there any way I can solve this problem? (I am using Windows 10, latest version of Python)
Error I got in windows 10 while executing a python script ->
Traceback (most recent call last):
File "C:\Users\YOUR NAME\Desktop\Sample.py", line 2, in
import psutil
ImportError: No module named psutil
This is how I resolved the issue ->
C:\python -m pip install --upgrade pip
[Latest pip version got installed successfully]
C:\>python -m pip install psutil
Collecting psutil
Downloading https://files.pythonhosted.org/packages/50/6a/34525bc4e6e153bf6e849a4c4e936742b365f6819c0462cebfa4f082a3c4/psutil-5.4.7-cp27-none-win_amd64.whl (220kB)
100% |UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU| 225kB 696kB/s
Installing collected packages: psutil
Successfully installed psutil-5.4.7
Finally, Sample.py got executed successfully
This worked for me..
sudo pip install --upgrade psutil
Follow these steps on windows:
Open command prompt in administrator mode
Enter Command python -m pip install psutil
Upgrade pip if outdated python -m pip install --upgrade pip
Process Example
I solved a problem and if you had a similar problem you should try this:
upgrade pip to the latest version (python -m pip install --upgrade pip)
delete psutil (C:\Users\(your username)\AppData\Local\Programs\Python\Python36-32\Lib\site-packages) if
you have it installed already
reupload psutilnow using pip install psutil
. It helped me and if you have a permission error, try opening cmd as administrator.
I had that problem trust me this works 100%. I am using VS Code you just have to install it with pip normally but sometimes it doesn't add it to your working directories (venv\lib\site-packages\) folder your editor is using. So just copy and paste it there from here C:\Users\(your username)\AppData\Roaming\Python\Python39\site-packages
I resolved this issue as below:
It seems, every time i was trying to upgrade psutil using "pip install psutil" it just showing the requirement is satisfied and showing 5.7.2.
Go to the folder where Python is install and psutil is available e.g.
"C:\Python\Lib\site-packages"
find all psutil related filesand rename them to something else e.g.
Old__psutil
Old_psutil-5.7.2.dist-info
Run "pip install psutil" from bash or command line
It updated for me to 5.8.0
This resolved my issue.
Inconsistencies can happen if you have multiple versions of windows installed on your system. Check for the default python directory path and make sure 'psutils' is updated in that directory.
I got the same issue and solved it by specifying the exact (virtual environment / global) pip you are using. In my case (using a virtual environment), after executed pip by using the absolute path, I installed psutil successfully.
I was having same issue, but not quite exactly the same circumstances. I am writing this for any people that have the same problem as I did.
I was running sudo python script.py (sudo was needed since I wanted to alter cpu frequencies) but Error : No module named 'psutil' appeared. I checked my python version with
python --version
and it was 3.8, but when I checked my version with
sudo python --version
it was running version 2.7. Once I ran
sudo python3 script.py
it ran smoothly. Of course I had already verified I had the newest pip installed + psutil library installed on python3. Basically, make sure you are running the correct python version and you have all libraries/package managers up to date, hope this helped!
This worked for me. I had multiple version of python in my ubuntu system.
$ sudo apt install python3.6-dev
These two commands typed in the SSH shell worked for me. The apt install is what was showing me the error mentioned.
sudo apt install pip
python3 -m pip install psutil
Result:
python3 -m pip install psutil
Collecting psutil
Downloading psutil-5.9.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (284 kB)
|████████████████████████████████| 284 kB 2.0 MB/s
Installing collected packages: psutil
Successfully installed psutil-5.9.1
Hope this helps someone...

'No module named requests' even if I installed requests with pip

I'm trying to test if requests module has been well installed. But I'm getting the following error :
raceback (most recent call last):
File "/Users/macbookpro/Desktop/test.py", line 1, in <module>
import requests
ImportError: No module named requests
when trying to run the following test script:
import requests
print 'test'
But I have installed requests with pip, and pip list command gives the following result :
MBPdeMacBook2:~ macbookpro$ pip list
arrow (0.7.0)
beautifulsoup4 (4.4.1)
classifier (1.6.5)
coursera-dl (0.6.1)
Django (1.8.6)
html5lib (1.0b8)
keyring (9.0)
lxml (3.6.0)
Pillow (3.4.2)
pip (8.0.2)
pyasn1 (0.1.9)
requests (2.14.2)
setuptools (19.4)
six (1.10.0)
urllib3 (1.16)
vboxapi (1.0)
virtualenv (13.1.2)
wheel (0.26.0)
Why requests isn't being imported ?
EDIT :
MBPdeMacBook2:~ macbookpro$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
MBPdeMacBook2:~ macbookpro$ which pip
/usr/local/bin/pip
MBPdeMacBook2:~ macbookpro$ python --version
Python 2.7.11
MBPdeMacBook2:~ macbookpro$ pip --version
pip 8.0.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
In general, you should get into the habit of working in a virtualenv. I find the documentation here to be helpful.
If you install all of your dependencies within the virtual environment, you'll be (mostly) sure that you are installing those deps. in the same environment that you're running the jobs in.
For your case, on the command line go to the directory where your code lives and run
pip install virtualenv
virtualenv my_project
source my_project/bin/activate
Now that the virtualenv is active you can
pip install requests
Only what is installed in the virtualenv will be available. This will keep your system clean. Each project should get its own virtualenv, meaning only the dependencies needed for each project will be available to them. This way you could, say, have version 1 of some dependency installed for one project and version 2 for another. They won't come into conflict.
After you have installed all the dependencies, run
pip freeze > requirements.txt
To get a list of all the dependencies for the project saved. Next time you need to install these, you simply run
pip install -r requirements.txt
Once you are done working in the virtualenv, run
deactivate
I am not 100% sure, but the paths from which python and which pip may indicate that you have two versions installed. The Python version being the old one that was shipped with OS X, and another version.
I would advice you to install Python27 (or even better Python3) from brew.
You can install brew with a single command, and another one for installing Python27/3. When this is done you set the PATH variable in your shell rc file and you should be good to go.
I have Python27 installed (via brew) and my (working environment) reports the following paths:
which python: /usr/local/bin/python
which pip: /usr/local/bin/pip
And
python --version: 2.7.15
pip --version: pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python2.7)
I experienced this same issue on Ubuntu 18.04 LTS, to check that, I first checked if requests library was installed on my system or not.
Run these commands on your terminal inside the virtual environment in which you working
$ python
Then the python command line opens, then run
>>> import requests
After this if you get an ImportError saying, No module named requests, then it means the dependency has not been installed properly. If there is no such error, then it means the dependency is installed successfully.
This can occur for example if pip is actually pip3 and python is actually python2.7.
In your case the which pip and which python eliminate this possibility but it just happened to me.
The solution was to do pip2 instead of pip; if the situation was reversed you can use pip3.
Simply go inside your virtual environment and run below commands:
1). pip install --user pipenv
2). pipenv install requests
after executing the above commands cd to your app folder inside the virtual environment and just run it. Hopefully now it will run.
Reference link: https://python-guide-pt-br.readthedocs.io/pt_BR/latest/dev/virtualenvs.html#make-sure-you-ve-got-python-pip

pip freeze not showing packages

For example if after installing Tornado with pip like this:
pip install tornado
Collecting tornado
...
Successfully installed backports-abc certifi singledispatch six tornado
pip freeze doesn't return tornado package in list, it just shows:
PyMySQL==0.7.2
also when I run easy_install it returns:
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/lib/python2.7/site-packages/
and your PYTHONPATH environment variable currently contains:
''
What is going wrong?
When using virtualenvwrapper or another virtual environment (which is probably not your case but is how I arrived at this question), you may have installed things using sudo which will install them for your entire system. (See here)
Therefore, pip freeze actually is working, you just haven't actually installed anything with that pip.
I suppose reinstalling pip may help you:
pip install --upgrade pip
To fix easy_install problem add /lib/python2.7/site-packages/ to your PYTHONPATH:
export PYTHONPATH=$PYTHONPATH:/lib/python2.7/site-packages/
Good Luck !
upgrade pip and it will work. I had the exact same problem. In my case it wasn't "sudo" related, but upgrading pip via pip install --upgrade pip solved the issue.

Unable to install pip on suse

Pretty new to linux/suse and python so excuse me if I cause some simple questions.
I've search through stackoverflow and haven't gotten a result for my question.
I'm running on Windows with a Virtual machine using SUSE. I'm trying to install py.test, but to install it, it needs either pip or easy_install. I've heard pip is preferred over easy_install, so I tried installing that with get-pip.py.
I run it with
python get-pip.py
and it tells me it has been installed, this is what it ouputs
Collecting pip
Using cached pip-6.1.1-py2.py3-none-any.whl
Collecting setuptools
Using cached setuptools-15.1-py2.py3-none-any.whl
Installing collected packages: pip, setuptools
Successfully installed pip-6.1.1 setuptools-15.1
I tried running
pip install -U pytest
however the command pip has not been found. I also looked into python-pip package via openSUSE, though I'm not sure how to open a .ymp file through a VM.
Would I have to add a path for it to work? Pointers would be appreciated.
It looks like pip was unstalled by a regular user, so it was installed under the user's homedir, thus needs to be explicitly added to the path.
On openSUSE I'd suggest installing it using YaST (as root) and it'll end up in /usr/bin/pip, shareable by all users. Here's how it looks like on openSUSE 13.2:
$> which pip
/usr/bin/pip
$> rpm -qf /usr/bin/pip
python3-pip-1.5.6-2.1.3.noarch
Just search for pip in the software management tool.
Also many additional python packages/modules come prepackaged as openSUSE RPMs, better check the software management tool 1st.

Installing python packages with multiple versions on OSX

I am attempting to install a package for python3.4 on Mac OSX 10.9.4. As you know, python ships with OSX, so when I installed python3.4 I was happy to find that it came with its own version of pip, that would install packages to it (installing pip on a mac with multiple versions of python will cause it to install on the system's python2.7.)
I had previously tried installing this package (https://pypi.python.org/pypi/chrome/0.0.1) with my first installation of pip (the one tied to python2.7) and found that it successfully installed on that version, but not on any others.
I ran an install with the new pip keyword for python3.4 (which when called by itself spits out the help page so i know it works) and it told me that the package was already installed and to try updating. The update revealed that I already had the most recent version. so I tried uninstalling it from just the python3.4 and reinstalling to no avail, and got the same results when uninstalling pip from python2.7 and reinstalling only on version 3.4.
I know that's a bit hard to follow but hopefully that makes sense.
I also reviewed the content here with no success.
RESOLVED:
while python did have a directory named the same as a directory it uses with packages, this was not the correct directory, for me it was in a subdirectory of library. while documentation said that referencing pip2 would cause the package to install on python3.4, this was false. however, referencing pip3.4 worked for me.
My suggestion is that you start using virtualenv.
Assuming you have 3.4 installed, then you should also have pyvenv. As for pip and 3.4, it should already be installed.
Using for example version 3.4 create your own virtual environment and activate it:
$ mkdir ~/venv
$ pyvenv-3.4 ~/venv/py34
$ source ~/venv/py34/bin/activate
$ deactive # does what is says...
$ source ~/venv/py34/bin/activate
$ pip install ... # whatever package you need
With version 2.7 first install virtualenv and then create your own virtual environment and activate it. Make sure that setuptools and pip are updated:
$ virtualenv-2.7 ~/venv/venv27
$ . ~/venv/venv27/bin/activate
$ pip install -U setuptools
$ pip install -U pip
$ pip install ... # whatever package you need

Categories