Error : No module named 'psutil' - python

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...

Related

Pip: adding directory to PATH

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

Python pip not working with egg_info error [duplicate]

I'm trying to install some packages with pip.
But pip install unroll gives me
Command "python setup.py egg_info" failed with error code 1 in
C:\Users\MARKAN~1\AppData\Local\Temp\pip-build-wa7uco0k\unroll\
How can I solve this?
About the error code
According to the Python documentation:
This module makes available standard errno system symbols. The value of each symbol is the corresponding integer value. The names and descriptions are borrowed from linux/include/errno.h, which should be pretty all-inclusive.
Error code 1 is defined in errno.h and means Operation not permitted.
About your error
Your setuptools do not appear to be installed. Just follow the Installation Instructions from the PyPI website.
If it's already installed, try
pip install --upgrade setuptools
If it's already up to date, check that the module ez_setup is not missing. If it is, then
pip install ez_setup
Then try again
pip install unroll
If it's still not working, maybe pip didn't install/upgrade setup_tools properly so you might want to try
easy_install -U setuptools
And again
pip install unroll
Here's a little guide explaining a little bit how I usually install new packages on Python + Windows. It seems you're using Windows paths, so this answer will stick to that particular SO:
I never use a system-wide Python installation. I only use virtualenvs, and usually I try to have the latest version of 2.x & 3.x.
My first attempt is always doing pip install package_i_want in some of my Visual Studio command prompts. What Visual Studio command prompt? Well, ideally the Visual Studio which matches the one which was used to build Python. For instance, let's say your Python installation says Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:40:30) [MSC v.1500 64 bit (AMD64)] on win32. The version of Visual Studio used to compile Python can be found here, so v1500 means I'd be using vs2008 x64 command prompt
If the previous step failed for some reason I just try using easy_install package_i_want
If the previous step failed for some reason I go to gohlke website and I check whether my package is available over there. If it's so, I'm lucky, I just download it into my virtualenv and then I just go to that location using a command prompt and I do pip install package_i_want.whl
If the previous step didn't succeed I'll just try to build the wheel myself and once it's generated I'll try to install it with pip install package_i_want.whl
Now, if we focus in your specific problem, where you're having a hard time installing the unroll package. It seems the fastest way to install it is doing something like this:
git clone https://github.com/Zulko/unroll
cd unroll && python setup.py bdist_wheel
Copy the generated unroll-0.1.0-py2-none-any.whl file from the created dist folder into your virtualenv.
pip install unroll-0.1.0-py2-none-any.whl
That way it will install without any problems. To check it really works, just login into the Python installation and try import unroll, it shouldn't complain.
One last note: This method works almost 99% of the time, and sometimes you'll find some pip packages which are specific to Unix or Mac OS X, in that case, when that happens I'm afraid the best way to get a Windows version is either posting some issues to the main developers or having some fun by yourself porting to Windows (typically a few hours if you're not lucky) :)
It was resolved after upgrading pip:
python -m pip install --upgrade pip
pip install "package-name"
I got stuck exactly with the same error with psycopg2. It looks like I skipped a few steps while installing Python and related packages.
sudo apt-get install python-dev libpq-dev
Go to your virtual env
pip install psycopg2
(In your case you need to replace psycopg2 with the package you have an issue with.)
It worked seamlessly.
I got this same error while installing mitmproxy using pip3. The below command fixed this:
pip3 install --upgrade setuptools
Download and install the Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-in/download/details.aspx?id=44266 - this package contains the compiler and set of system headers necessary for producing binary wheels for Python 2.7 packages.
Open a command prompt in elevated mode (run as administrator)
Firstly do pip install ez_setup
Then do pip install unroll (It will start installing numpy, music21, decorator, imageio, tqdm, moviepy, unroll) # Please be patient for music21 installation
Python 2.7.11 64 bit used
Other way:
sudo apt-get install python-psycopg2 python-mysqldb
I had the same issue when installing the "Twisted" library and solved it by running the following command on Ubuntu 16.04 (Xenial Xerus):
sudo apt-get install python-setuptools python-dev build-essential
It's a dependency issue.
I tried running the following commands helped me sorting out the dependencies, in my case the dependency was
grpcio
pip3 install --upgrade pip
python3 -m pip install --upgrade setuptools
pip3 install --no-cache-dir --force-reinstall -Iv grpcio==1.36.1
pip3 install pulsar-client==2.7.0
remember you must have python3 installed in your system.
First try:
pip install unroll
For sure not work :)
Then Try:
pip2 install unroll
Still get error Try:
pip3 install unroll
If pip3 Worked then suggest to change configuration to use pip3 as pip because you will get a lot of issues as the modern now is Python3 = pip3 if you execute a script files.
I had the same problem.
The problem was:
pyparsing 2.2 was already installed and my requirements.txt was trying to install pyparsing 2.0.1 which throw this error
Context: I was using virtualenv, and it seems the 2.2 came from my global OS Python site-packages, but even with --no-site-packages flag (now by default in last virtualenv) the 2.2 was still present. Surely because I installed Python from their website and it added Python libraries to my $PATH.
Maybe a pip install --ignore-installed would have worked.
Solution: as I needed to move forwards, I just removed the pyparsing==2.0.1 from my requirements.txt.
I ran into the same error code when trying to install a Python module with pip.
#Hackndo noted that the documentation indicate a security issue.
Based on that answer, my problem was solved by running the pip install command with sudo prefixed:
sudo pip install python-mpd2
For me this worked
python3 -m pip3 install -U pip
you can also try
python -m pip install -U pip
pip3 install --upgrade setuptools
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with -m pip instead of running pip directly.
Use python3 -m pip "command", eg:
python3 -m pip install --user pyqt5
I tried all of the above with no success. I then updated my Python version from 2.7.10 to 2.7.13, and it resolved the problems that I was experiencing.
That means some packages in pip are old or not correctly installed.
Try checking version and then upgrading pip.Use auto remove if that works.
If the pip command shows an error all the time for any command or it freezes, etc.
The best solution is to uninstall it or remove it completely.
Install a fresh pip and then update and upgrade your system.
I have given a solution to installing pip fresh here - python: can't open file get-pip.py error 2] no such file or directory
next installation helps me:
pip3 install cython
This worked for me:
sudo xcodebuild -license
Upgrading Python to version 3 fixed my problem. Nothing else did.
I downloaded the .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ and then did:
pip install scipy-0.19.1-cp27-cp27m-win32.whl
Note that the version you need to use (win32/win_amd-64) depends on the version of Python and not that of Windows.
I had this problem using virtualenvs (with pipenv) on my new development setup.
I could only solve it by upgrading the psycopg2 version from 2.6.2 to 2.7.3.
More information is at https://github.com/psycopg/psycopg2/issues/594
I faced the same problem with the same error message but on Ubuntu 16.04 LTS (Xenial Xerus) instead:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-w71uo1rg/poster/
I tested all the solutions provided above and none of them worked for me. I read the full TraceBack and found out I had to create the virtual environment with Python version 2.7 instead (the default one uses Python 3.5 instead):
virtualenv --python=/usr/bin/python2.7 my_venv
Once I activated it, I run pip install unirest successfully.
try on linux:
sudo apt install python-pip python-bluez libbluetooth-dev libboost-python-dev libboost-thread-dev libglib2.0-dev bluez bluez-hcidump
Had the same problem on my Win10 PC with different packages and tried everything mentioned so far.
Finally solved it by disabling Comodo Auto-Containment.
Since nobody has mentioned it yet, I hope it helps someone.
I had the same problem and was able to fix by doing the following.
Windows Python needs Visual C++ libraries installed via the SDK to build code, such as via setuptools.extension.Extension or numpy.distutils.core.Extension. For example, building f2py modules in Windows with Python requires Visual C++ SDK as installed above. On Linux and Mac, the C++ libraries are installed with the compiler.
https://www.scivision.co/python-windows-visual-c++-14-required/
Following below command worked for me
[root#sandbox ~]# pip install google-api-python-client==1.6.4
Methods to solve setup.pu egg_info issue when updating setuptools or not other methods doesnot works.
If CONDA version of the library is available to install use conda instead of pip.
Clone the library repo and then try installation by pip install -e . or by python setup.py install
upgrading python's version did the work for me.
I have just encountered the same problem when trying to pip install -e . a new repo. I did not notice that the contents of setup.py haven't been saved properly and I was effectively running the command with an empty setup.py.
Hence you may experience the same error message if the setup.py of the target package is either empty or malformed.
I solved it on Centos 7 by using:
sudo yum install libcurl-devel

'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

No module named google.protobuf

I am trying to run Google's deep dream. For some odd reason I keep getting
ImportError: No module named google.protobuf
after trying to import protobuf. I have installed protobuf using sudo install protobuf. I am running python 2.7 OSX Yosemite 10.10.3.
I think it may be a deployment location issue but i cant find anything on the web about it. Currently deploying to /usr/local/lib/python2.7/site-packages.
There is another possibility, if you are running a python 2.7.11 or other similar versions,
sudo pip install protobuf
is ok.
But if you are in a anaconda environment, you should use
conda install protobuf
Locating the google directory in the site-packages directory (for the proper latter directory, of course) and manually creating an (empty) __init__.py resolved this issue for me.
(Note that within this directory is the protobuf directory but my installation of Python 2.7 did not accept the new-style packages so the __init__.py was required, even if empty, to identify the folder as a package folder.)
...In case this helps anyone in the future.
In my case I
downloaded the source code, compiled and installed:
$ ./configure
$ make
$ make check
$ sudo make install`
for python I located its folder(python) under source code, and ran commands:
$ python setup.py build
$ python setup.py install'
Not sure if this could help you..
I got the same error message when I tried to use Tensor Flow. The solution was simply to uninstall Tensor Flow and protobuf:
$ sudo pip uninstall protobuf
$ sudo pip uninstall tensorflow
And reinstall it again: pip installation of Tensorflow. Currently, this is:
# Ubuntu/Linux 64-bit, CPU only:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Ubuntu/Linux 64-bit, GPU enabled:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0rc0-cp27-none-linux_x86_64.whl
# Mac OS X, CPU only:
$ sudo easy_install --upgrade six
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0rc0-py2-none-any.whl
when I command pip install protobuf, I get the error:
Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
If you have the same problem as me, you should do the following commands.
pip install --ignore-installed six
sudo pip install protobuf
According to your comments, you have multiply versions of python
what could happend is that you install the package with pip of anthor python
pip is actually link to script that donwload and install your package.
two possible solutions:
go to $(PYTHONPATH)/Scripts and run pip from that folder that way you insure
you use the correct pip
create alias to pip which points to $(PYTHONPATH)/Scripts/pip and then run pip install
how will you know it worked?
Simple if the new pip is used the package will be install successfully, otherwise the package is already installed
I installed the protobuf with this command:
conda install -c anaconda protobuf=2.6.1
(you should check the version of protobuf)
In my case, MacOS has the permission control.
sudo -H pip3 install protobuf
I had this problem to when I had a google.py file in my project files.
It is quite easy to reproduce.
main.py: import tensorflow as tf
google.py: print("Protobuf error due to google.py")
Not sure if this is a bug and where to report it.

Installing pip for an offline machine on Python 2.7, CentOS 6.3

I'm trying to install lxml for Centos6.3, due to this issue. It looks like I've got a conflicting version of pip. The standing solution seems to re-install pip for the correct version of python.
My main issue is that all the methods I've found for installing pip require an internet connection. Is it possible to download pip install files, and then run pip install -U pip and point it at the right files?
The PyPI page for pip only has pip6.11 as a .whl. I've tried running pip install -U pip-6.1.1-py2.py3-none-any.whl and it's not worked.
I'm stumped. How do I install it?
You could try to download pip and setuptools manually from: https://pypi.org/project/pip/#files and https://pypi.org/project/setuptools/#files
get the python pip script from: https://bootstrap.pypa.io/get-pip.py
after that unzip/untar packages and run:
python get-pip.py --no-index --find-links=/path/to/pip-and-setuptools
or alternatively trying:
python setup.py install when running in unpacked folders
More here: https://github.com/pypa/pip/issues/2351

Categories