ModuleNotFoundError: No module named 'yyy' in Windows Shell - python

I'm using Python 3.6 on Windows 7.
I have a script that uses standard python packages.
The script run fine from IDLE.
It used to run fine from Windows command too, but not anymore.
I don't know why. It complains about missing package like:
, line 4, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
The path looks ok (I've added all path found from IDLE / Path Browser):
PATH=C:\Users\olivier\AppData\Local\Programs\Python\Python36\lib\site-packages;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Lib;C:\Users\olivier\AppData\Local\Programs\Python\Python36\DLLs;C:\Users\olivier\AppData\Local\Programs\Python\Python36\python36.zip;C:\Users\olivier\AppData\Local\Programs\Python\Python36\Scripts\;C:\Users\olivier\AppData\Local\Programs\Python\Python36\;C:\Users\olivier\AppData\Local\GitHubDesktop\bin
Any idea?
Thanks

I had the same problems. Did you try to install it through pip and did you try to install on the strict path by using pip install --target="..." for e.g "pip install --target=C:\U2\UV\python\Lib\site-packages geopy" and pasting it in python console?
Also look at this post: Install a module using pip for specific python version

These two points can help you to solve the problem as per my knowledge.
Are you using two Python versions?
Check the Environmental Variables and if everything is fine there, it's better to uninstall and reinstall it again. use pip for installing and uninstalling

Related

ModuleNotFoundError: No module named 'fpdf'

Getting this error: ModuleNotFoundError: No module named 'fpdf'
I've re-downloaded python, created a new venv and installed fpdf2 using pip install fpdf2, but I still get this error when I run from fpdf import FPDF
python version: 3.10.4
I've looked all over stack overflow and through the github issues and haven't found any solutions, and have no idea what to try next.
firstly please make sure that you want fpdf or fpdf2 lib, these are two different lib.
It seems that you want fpdf, so you need to try:
pip install fpdf
I was using VSCode's Jupyter extension and it wasn't using the same virtual environment that the terminal was using - so the install wasn't going to the right place. Once I aligned the two virtual environments, it worked fine.
This may be silly but should you be using fpdf2 instead of fpdf? Because if that's the name then it needs to be exact.
from fpdf2 import FPDF
Otherwise if you are using an IDE, then you may need to download the package into the IDE. For example in PyCharm I had to go to Python Packages and install it through there even after pip. Probably some path related issue.
Try pip install fpdf
With no 2.
Also make sure you're in the same env.

ModuleNotFoundError from Visual Studio after installing Python modules with "pip" on the command line

I am trying to install modules like tkinter, bs4 and numpy.
I use cmd and pip to install them, and it says that everything is installed fine.
When I am using Visual Studio code it says
ModuleNotFoundError: No module named '....'
How can I find out if Python and the modules are in the same PATH?
Or what can i do to fix that?
I've tried to reinstall Python, but I get the same error.
Is it just the VSC?
File "c:/Users/Γιώργος Μαργα/Desktop/test.py", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
pip install is most likely installing globally into a Python interpreter that is different than the one that you have selected in VS Code.
if vscode not recognize your modules try to reload vscode.
install modules with
python3 -m pip install {new_module}
and then reload your Vs code
make sure to set your Python interpreter within VSCode to the same as the one in your system path pythoninvscode
Ok so i uninstall python and installed it again but this time i checked the box that said add that to PATH or someithng like this.
I also uninstalled python from the windowsstore however when it ry to run a code in VSC it doesnt do anything

Python module shows up in pip freeze, but cannot be imported

I'm in Win10 and use vanilla Python 3.7.3 (e.g. not conda or anything). I had a successful pip install for the package, the package shows up in pip freeze, and the package is supposed to be compatible with my version of Python. I've seen several threads with similar issues on OS X and Linux, and have tried to emulate their solutions on Windows, but no luck. I'm guessing it could be an issue with my PATH variable, but I'm not quite sure. The error I get when trying to import is the "No module named" error.
Went into site-packages...for some reason the module was named Bio there (everywhere else it's named biopython, again, including pip freeze) and importing that worked. Not sure if this was just a bad dev choice or what.

Conflicts when installing Anaconda Python

I have recently installed the Anaconda distribution of Python. I then inserted the following line into my .bashrc file:
export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH
So, there are now two python binary files: one in /usr/bin/, and one in /home/karnivaurus/Libraries/Anaconda/bin.
I also have a python script, which attempts to import a module named caffe, with the line import caffe. Now, if I run python caffe from the terminal, the script runs fine. However, if I open the script in PyCharm, and set the interpreter to be /home/karnivaurus/Libraries/Anaconda/bin/python, I get the following error:
ImportError: No module named caffe
Based on all this, I have two questions....
If I run the python command from the terminal, which binary file would it execute? The one in /usr/bin, or the one in /home/karnivaurus/Libraries/Anaconda/bin? My intuition is that it runs the first one, due to the discrepancy in behaviour with PyCharm. In that case, how can I force my system to use the Anaconda version?
If I install a new package, for example pip install caffe, then where will it be installed to? Will it be installed to /usr/local/lib/python2.7/site-packages, or to /home/karnivaurus/Libraries/Anaconda/pkgs? How can I be sure that my python command will know where to find the new package?
Thank you!
Answer to 1:
Based on your example: export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH the /home/karnivaurus/Libraries/Anaconda/bin comes first, so the python from there should be the one to be executed.
But the definite answer depends on result of running: which python.
Answer to 2:
In Anaconda, use conda instead of pip to install packages. When you install using pip install caffe you'll be installing to /usr/local/lib/python2.7/site-packages.
Use conda install caffe to install to /home/karnivaurus/Libraries/Anaconda/pkgs.
Above two answers explain why even if you pip install spam package, python would say ImportError: No module named spam. Essentially you install to ordinary Python, but you attempt to import in Anaconda's python.

ImportError: no module named win32api

I am using Python 2.7 and I want to use pywin32-214 on Windows 7. I installed pywin32-214 by using the MSI installer. But when I import win32api in my Python script, it throws the error:
no module named win32api
What should I do? How can I use win32api on Windows 7?
This is resolve my case as found on
Where to find the win32api module for Python?
pip install pypiwin32
According to pywin32 github you must run
pip install pywin32
and after that, you must run
python Scripts/pywin32_postinstall.py -install
I know I'm reviving an old thread, but I just had this problem and this was the only way to solve it.
I had an identical problem, which I solved by restarting my Python editor and shell. I had installed pywin32 but the new modules were not picked up until the restarts.
If you've already done that, do a search in your Python installation for win32api and you should find win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32.
I didn't find the package of the most voted answer in my Python 3 dist.
I had the same problem and solved it installing the module pywin32:
In a normal python:
pip install pywin32
In anaconda:
conda install pywin32
My python installation (Intel® Distribution for Python) had some kind of dependency problem and was giving this error. After installing this module it stopped appearing.
I had both pywin32 and pipywin32 installed like suggested in previous answer, but I still did not have a folder ${PYTHON_HOME}\Lib\site-packages\win32.
This always lead to errors when trying import win32api.
The simple solution was to uninstall both packages and reinstall pywin32:
pip uninstall pipywin32
pip uninstall pywin32
pip install pywin32
Then restart Python (and Jupyter).
Now, the win32 folder is there and the import works fine. Problem solved.
After installing pywin32
Steps to correctly install your module (pywin32)
First search where is your python pip is present
1a. For Example in my case location of pip -
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
Then open your command prompt and change directory to your pip folder location.
cd C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts
C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>pip install
pypiwin32
Restart your IDE
All done now you can use the module .
The following should work:
pip install pywin32
But it didn't for me. I fixed this by downloading and installing the exe from here:
https://github.com/mhammond/pywin32/releases
This line:
import win32com
got me the error no module named win32api.
Using this command in elevated terminal:
pip install pywin32-ctypes and
pip install pywin32
and based on the error displayed, replacing:
import win32api → from win32ctypes.pywin32 import win32api
import pywintypes → from win32.lib import pywintypes
import _win32sysloader → from win32 import _win32sysloader
in your source file, or even the files of the packages that report the error (know what you are doing if you choose this approach) may solve this error. But better would be to just add the corresponding directories into the python path variable, for better integration with the python loading system, more info here: https://realpython.com/python-import/
So I put this content:
python38.zip
.
./lib
./lib/site-packages
./lib/site-packages/win32
./lib/site-packages/win32/lib
./lib/site-packages/win32ctypes/pywin32
./lib/site-packages/win32ctypes
# Uncomment to run site.main() automatically
#import site
(order DOES matter)
into this file: <python_root_installation_directory>/python38._pth
That way, correct libraries load when standard imports are used. If there is a cache import somewhere in the library, it will work, and the imports inside the libraries work as well.
This works for me and my installation, so your environment may be set up differently and this guide may not be fully compatible, but it is a good step in solving the issue, maybe modification or extension of my steps above may lead to the solution in another distribution.
Try this, it worked for me, it may help you!
pip install pywin32==225
I've tried all of your answers and finally got a solution. my issue was that I installed from both pip and python interpreter on my Pycharm IDE. I just removed win32compact from my interpreter and it works.
let me summarize, correct me if wrong, as below:
# update to newest pywin32
python -m pip install -U pywin32 pypiwin32
# run the post-install #ref https://stackoverflow.com/questions/21343774/importerror-no-module-named-win32api
python %CONDA_PREFIX%\Scripts\pywin32_postinstall.py -install
# double check
python -c "print( __import__('win32api') )"
In my case, the only thing that worked was to download the appropriate wheel from: https://pypi.org/project/pywin32/#files, and install with --force-reinstall.
pip install pywin32-300-cp37-cp37m-win_amd64.whl --force-reinstall
I found solution here:
https://www.ti-enxame.com/pt/python/pywin32-e-python-3.8.0/813327700/
I was able to run it on Spyder without error, but It wasn't working on cmd prompt
I just import the module pywintypes before win32api
import pywintypes
import win32api
I tried to reinstall pywin32, installed different versions, but nothing could make pywin work. The only thing that did finally help me was running
python pywin32_postinstall.py
which is located at Anaconda3\Scripts folder. Thanks for sameer_nubia for highlighting the location.
I solve this by
python -m pip install -U pywin32 pypiwin32

Categories

Resources