When I run my code that includes psutil module I encounter the following error:
Traceback (most recent call last):
File "/Users/alek/Desktop/coloring/solver.py", line 4, in <module>
from psutil import cpu_count
ModuleNotFoundError: No module named 'psutil'
Although, when trying to install the module in terminal, I can see the following
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: psutil in /opt/homebrew/lib/python3.9/site-packages (5.9.1)
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
WARNING: There was an error checking the latest version of pip.
How should I ensure that the module is in the right environment and can be used by my program?
Thanks in advance!
try to upgrade it
sudo pip install --upgrade psutil
try to run this command in python shell:
import site
site.getsitepackages()
actually, it is trying to search psutil module in one of the Xcode path.
see if you have psutil in this path:
/Applications/Xcode_13.4.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages
if not add the psutil module here and it should work.
it worked for me.
Related
I wanted to run a script that would scan my network and that script uses a awesome library called who-is-on-my-wifi. I have installed the module to run the script but i get errors from the prompt saying that it cannot detect such a module in the system.
This is the script.
from who_is_on_my_wifi import *
WHO = who()
for i in range(0, len(WHO)):
print(WHO[i])
And this is the error that i get.
python scanner.py
Traceback (most recent call last):
File "scanner.py", line 1, in <module>
from who_is_on_my_wifi import *
ImportError: No module named who_is_on_my_wifi
This is the proof that i have installed the module
pip3 install 'who_is_on_my_wifi'
Requirement already satisfied: who_is_on_my_wifi in /home/harein/.local/lib/python3.8/site-packages (1.2.0)
Requirement already satisfied: getmac in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.8.2)
Requirement already satisfied: python-nmap in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.6.1)
Any suggestions on how i can avoid this can continue executing my script ?
EDIT
The script finally executed the way i want by changing the,
python scanner.py to python3 scanner.py
You guys were right, it was the way how i executed the script that generated this error and it was not a problem in the module apparently.
I would like to thank everyone who gave the support.<3
When trying to
import this_is_not_a_module
the error you get:
ImportError: No module named this_is_not_a_module
is the error raised by Python 2.
Python 3 would raise a different one:
ModuleNotFoundError: No module named 'this_is_not_a_module'
So, your actual problem is that your system tries to execute your script with some Python 2 version, while you installed your module for your Python 3.8 version.
sometimes you can't import modules because you have installed two python versions(or conda along with it). if you have, delete one of your python versions or activate conda and try importing your module, or just try:
pip uninstall who_is_on_my_wifi
pip install who_is_on_my_wifi
I usually tend to install modules per project and use virtualenv for it.
It kind of links respective versions of programs (like python interpreter, pip and so on) and takes care of PYTHONPATH and the way of installed dependencies.
$ pip3 install virtualenv
$ virtualenv whoisonwifi
$ source whoisonwifi/bin/activate
$ pip --version
pip 21.0.1 from
/mnt/devel/workonhome/whoisonwifi/lib/python3.7/site-packages/pip
(python 3.7)
$ pip install 'who_is_on_my_wifi'
from there your code (sort of) works for me.
I am trying to set up ortools on my Mac.
I installed via pip install ortools. I can verify that the package installed successfully.
conda list | grep ortools
WARNING: The conda.compat module is deprecated and will be removed in a future release.
ortools 7.1.6720 pypi_0 pypi
When I try to use the library, it looks like there are missing functions. I followed along with the example here:
https://developers.google.com/optimization/introduction/python
This returns an error:
from __future__ import print_function
from ortools.linear_solver import pywraplp
Traceback (most recent call last):
File "simple_ortools_example.py", line 2, in <module>
from ortools.linear_solver import pywraplp
ImportError: No module named ortools.linear_solver
I can import the module otherwise and look at the functions interactively:
>>> ortools.__
ortools.__cached__ ortools.__gt__( ortools.__path__
ortools.__class__( ortools.__hash__( ortools.__reduce__(
ortools.__delattr__( ortools.__init__( ortools.__reduce_ex__(
ortools.__dict__ ortools.__init_subclass__( ortools.__repr__(
ortools.__dir__( ortools.__le__( ortools.__setattr__(
ortools.__doc__ ortools.__loader__ ortools.__sizeof__(
ortools.__eq__( ortools.__lt__( ortools.__spec__
ortools.__file__ ortools.__name__ ortools.__str__(
ortools.__format__( ortools.__ne__( ortools.__subclasshook__(
ortools.__ge__( ortools.__new__( ortools.__version__
ortools.__getattribute__( ortools.__package__
I just used tab complete here to see what was available. Sure enough there is no linear_solver attached to the ortools module.
I'm a bit at a loss as to what to try next. Any advice would be apreciated.
I downgraded to an earlier version which solves the problem.
pip install ortools==6.7.4973
I faced the same issue today on Windows. Figured out that it is usually caused due to missing Microsoft Visual Studio 20** redistributables c++ (see here).
This is how I solved it (Python 3.7.6, ortools Version: 7.5.*).
Got the latest Microsoft Visual Studio 20** redistributables c++ from https://support.microsoft.com/en-my/help/2977003/the-latest-supported-visual-c
downloads
Installed it and Restarted the computer.
Uninstall the ortools 'python -m pip uninstall ortools'
Install back the ortools 'python -m pip install --user ortools'
Validated installation with python -c "from ortools.linear_solver import pywraplp"
So I have a virtual environment where I installed the package utility. I know I installed it because when I do pip install utlity and get this output:
Requirement already satisfied: utility in ./anaconda3/envs/SpliceBuster/lib/python3.5/site-packages (1.0)
Here's the output of print (sys.path):
['', '/home/joel/anaconda3/envs/SpliceBuster/lib/python35.zip', '/home/joel/anaconda3/envs/SpliceBuster/lib/python3.5', '/home/joel/anaconda3/envs/SpliceBuster/lib/python3.5/plat-linux', '/home/joel/anaconda3/envs/SpliceBuster/lib/python3.5/lib-dynload', '/home/joel/anaconda3/envs/SpliceBuster/lib/python3.5/site-packages']
When I do import utility in a python shell, I get:
Traceback (most recent call last):
File "<stdin>", line 1, in
ImportError: No module named 'utility'
It's confusing to me because I can import numpy, and when I do pip install numpy, the output is:
Requirement already satisfied: numpy in ./anaconda3/envs/SpliceBuster/lib/python3.5/site-packages (1.12.1)
which means that both utility and numpy are installed in the same folder, but numpy is found whereas utility isn't.
Any thoughts on what could be going on?
Other info:
which python:
/home/joel/anaconda3/envs/SpliceBuster/bin/python
python -V:
Python 3.5.0 :: Continuum Analytics, Inc.
Are you sure you want to use this package? Looking at Pypi there seems to be no description and the source code of the project is nowhere to be found.
Looking at the package content, it's clear the setup.py is incomplete as well as the package itself.
The name to import is utilitybelt and not utility, yet you will encounter other importing issues as the package depends on other third party modules which are not listed in the setup.py.
Try to place the module's folder into the same directory where you have the script you want to execute. This way we could discard a folders' tree issue.
Update 2:
the main problem turned out to be a different one from what I had thought it was, and asked for help here. I moved the new question to a new post:
Install custom python package in virtualenv
Update:
ok, so I screwed up my non-virtualenv by accident.
The non-virtualenv (normal bash) I could easily fix by removing the manually installed (via pip) lxml and running
conda install lxml --force
But for some reason, that doesn't work in the virtualenv.
There, running
conda install lxml --force
works without error message, but when I run python and simply say
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named lxml
Any suggestions??
old message:
I'm trying to use virtualenv for my python flask application.
The python code runs perfectly fine without the virtualenv.
I've installed the packages I need in the virtualenv, but I after installing lxml via
pip install lxml
Installing collected packages: lxml
Successfully installed lxml-3.6.0
I get the following error message when running my code:
File "/Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/docx-0.2.4-py2.7.egg/docx.py", line 17, in <module>
from lxml import etree
ImportError: dlopen(/Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/lxml/etree.so, 2): Library not loaded: libxml2.2.dylib
Referenced from: /Users/XXX/xxx/flask-aws/lib/python2.7/site-packages/lxml/etree.so
Reason: Incompatible library version: etree.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0
I have seen other people report similar problems at stackoverflow, and one guy remarked that the problem might related to the virtualenv, but there was no solution.
Once again: The python code runs perfectly fine without virtualenv! But inside virtualenv, I can't get it to work.
I'm using Anaconda Python 2.7 on a Mac.
I'd appreciate any help guys!
I had the same error and stumbled upon this link, after searching for the incompatible library error "libxml2.2.dylib provides version 10.0.0"
Installing libxml2 that worked for me:
brew install libxml2
brew link --force libxml2
Solution that works for me in virtual environment is to force pip to recompile lxml:
pip install lxml --force-reinstall --ignore-installed --no-binary :all:
I am working with pycrypto. It works fine on my local windows machine, but when I move it to my python box I get an error with importing the module:
from Crypto.Cipher import ARC4
ImportError: No module named 'Crypto'
The output of python3.3 -c "from Crypto.Cipher import ARC4"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'Crypto'
output of pip3 list has a reference includes pycrypto (2.6.1)
I know it works with Python 2.7.6, but I wrote the script in 3.3 so it depends on some things from 3.3
As I already wrote in this answer:
WARNING: Don't use pycrypto anymore!
Use pycryptodome instead, via pip3 install pycryptodome.
But make sure that you don't have pycrypto installed, because both packages install under the same folder Crypto.
I am assuming that your "python box" is a remote computer.
First, make sure pycrypto is up to date (pip3 install --upgrade pycrypto). The older versions may not be compatible with python 3.3
If that doesn't work, try looking in site-packages (the directory) to make sure the functions actually exist.
If none of that works, it might be easier (just a suggestion) to use from future import the things you need. That way it is python 2&3 compatible.
Use pycryptodome, either install using pip or in case using IDE like pycharm install as a package via Preferences.
In case still gives error, use pycryptodomex (different from pycryptodome).
You will not see any error in importing from Cryptodome.Cipher import AES