ModuleNotFoundError: No module named 'win32api - python-3.x

I am using embedded python 3.7.4
Getting the folliwng error when trying to create new file in jupyter notebook
File "D:\Users\sgangop7\python3.7.4\Lib\site-packages\jupyter_core\paths.py", line 387, in win32_restrict_file_to_user
import win32api
ModuleNotFoundError: No module named 'win32api'
Solutions Tried:
fresh install of jupyter notebook
pip install pypiwin32
pip install pywin32
Running the pywin32_postinstall.py
Added 'D:\Users\sgangop7\python3.7.4\Lib\site-packages' in the PATH variable of environment variable
Copied 'win32api.pyd' to 'D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib'
I cannot find any other solution for how to fix this issue.

On your jupyter notebook, you can try these commands :
import sys
sys.path
You will see a list of paths which Python is using to find packages. If your path "D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib" isn't in the list, you may need to add it. You can do it like this :
sys.path.insert("D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib")
Good luck !

Related

Tensorflow installed can't be imported

I'm trying to import tensorflow. But even after installing it, it doesn't seem to be recognized.
>conda create -n tf tensorflow
>conda activate tf
(tf)>pip install --ignore-installed --upgrade tensorflow==1.15 --user
...
Successfully installed absl-py-0.9.0 astor-0.8.1 gast-0.2.2 google-pasta-0.2.0 grpcio-1.28.1 h5py-2.10.0 keras-applications-1.0.8 keras-preprocessing-1.1.0 markdown-3.2.1 numpy-1.18.2 opt-einsum-3.2.0 protobuf-3.11.3 setuptools-46.1.3 six-1.14.0 tensorboard-1.15.0 tensorflow-1.15.0 tensorflow-estimator-1.15.1 termcolor-1.1.0 werkzeug-1.0.1 wheel-0.34.2 wrapt-1.12.1
(tf) C:\Users\antoi\Documents\Programming\Covent Garden\covent_garden_ds>python3 app.py
Traceback (most recent call last):
File "app.py", line 4, in <module>
from tensorflow.keras.callbacks import ModelCheckpoint
ModuleNotFoundError: No module named 'tensorflow'
Python3 is there:
(tf) C:\Users\antoi\Documents\Programming\Covent Garden\covent_garden_ds>where python3
C:\Users\antoi\AppData\Local\Microsoft\WindowsApps\python3.exe
It's not the one I should be using, isn't it?
What version of Python are you running? In order to both successfully import and run the Tensorflow module, you must have the 64 bit version of Python installed. If you are using the latest version of Python, which to the best of my knowledge is 3.8.2, completely uninstall that version of Python, and downgrade to the latest Python version with 64 bit support.
If you follow the output of pip --version to find where your anaconda files are located, you can find the anaconda python executable, usually about two directory levels higher (if pip is in C:\example\anaconda\lib\site-packages, then python is probably in C:\example\anaconda) and use a full path to that python executable to run the file like C:\example\anaconda\python app.py. Or you could update your path environment variable to replace C:\Users\antoi\AppData\Local\Microsoft\WindowsApps\ with the directory containing the anaconda python executable
I've had this same exact issue (but on macOS) several times before I realized what was wrong, and I've seen several others have this issue too. I wish there was a way Python could somehow better regulate this to make sure the default executables for pip and python are always in sync

ModuleNotFoundError when run python script but in cmd prompt type 'import colorama' is works

Window10 and Python3.7.4
The lib I am trying to use is 'colorama'.
When i run the python script file (x.py) it cannot find the module in the line which is "import colorama", but when i open a cmd and enter python env then type 'import colorama', it works. Does any one know what's the reason?
'''
>>>D:\Scratch\commands>mypythonscript.py
>>>Traceback (most recent call last):
>>> File "D:\Scratch\commands\mypythonscript.py", line 12, in <module>
>>> from colorama import init, Fore, Back, Style
>>>ModuleNotFoundError: No module named 'colorama'
'''
I don't know why this issue arise but maybe I installed VS2019. Before this, it worked fine for me.
Try to find which python your are working with using SYS module with its VERSION method in this way:
import sys
print(sys.version)
And then verify if you are using the same python version as you are using on cmd.
Another problem could be the path of your module, try to locate it with the "magical method" of your module installed, for example in this case:
import colorama
print(colorama.__file__)
And then verify if colorama is in this path: ".../Python37/lib/site-packages/colorama"
if not, download COLORAMA from here:
https://www.lfd.uci.edu/~gohlke/pythonlibs/
unzip it with 7ZIP
and all unzip files copy to : ".../Python37/lib/site-packages"
don't worry for the module version, colorama is for all python versions.
NOTE: this only works for windows version.

"" ModuleNotFoundError: No module named 'geopy' ""

I can't seem to use a module in Jupyter notebooks that was successfully installed to my mac via pip3 install geopy.
I do not understand anything about working directory, where the module is being sent after download, or where jupyternotebooks is grabbing modules when you import them. Please help
import geopy
ModuleNotFoundError: No module named 'geopy'
If you want to use a particular package in a jupyter notebook you can use the following command in a code cell in a jupyter notebook.
!pip install geopy
In the next code cell you can try
import geopy
This will at the least ensure you have the package to use within the jupyter notebook.
You may want to read this text for details on python and pip

Jupyter Notebook Packages Won't Import

I've searched around for a while, and I've tried many things such as
conda create -n ipykernel_py3 python=3 ipykernel
source activate ipykernel_py3 # On Windows, remove the word 'source'
python -m ipykernel install --user
Uninstalling and reinstall both Python3 and Anaconda3. All I want is for Jupyter Notebook to be able to use libraries in Anaconda. If I change my environment to root via
activate root
I can open Jupyter notebook, however when I do
activate ipykernel_py3
and then try to do
jupyter notebook
I get the error
Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2
When I open Jupyter notebook and input
import os
os.getcwd()
I get
'C:\Users\Mike\Documents\Mathematical Modeling'
and Anaconda is in
'C:\ProgramData\Anaconda3'
The problem is when I do
import numpy
I get this error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
ModuleNotFoundError: No module named 'numpy'
--------------------------------------EDIT--------------------------------------
I've just uninstalled anaconda, and am currently reinstalling it. For some reason I was unable to install other packages to my ipykernel_py3 environment. Hopefully I figure something out.
The solution after countless re-installations of anaconda, and working with environments, is this
Go to start menu->
View Advanced System Settings->Environment Variables
highlight the variable that has name 'Path'
Click edit
Change variable value to 'C:\Users\Mike\Anaconda3\Scripts'
Of course my directory will be different from anyone else's, but this solved all my problems.

Pyinstaller --onefile ImportError: No module named 'win32api'

Problem statement:
I can't seem to run
'PyInstaller --onefile myfile.py'
on a file containing
import wmi
It cannot find win32api. I get a popup warning saying python has stopped etc. My console says "ImportError: No module named 'win32api'". I can run 'import win32api', 'import win32com', and 'import WMI' in python directly in the same environment without issue. I fundamentally don't understand what is wrong here.
Error message:
3469 INFO: Loading module hook "hook-pywintypes.py"...
Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named 'win32api'
I have tried:
PyInstaller - ImportError: No module named win32api - 'import os' works fine for PyInstaller and runs fine in python.
No module named 'win32api' - Not very helpful
How to install pywin32 module in windows 7 - This is where I got the SF link (python3.5 amd64 pywin32 version)
ImportError: no module named win32api -
I thought it might be a path thing, but my installation appears to be in the correct place: "C:\Users\myuser\AppData\Local\Continuum\Anaconda3\pkgs\pywin32-220-py35_2\Lib\site-packages\win32"
I can run 'PyInstaller --onefile myscript.py' on other files, and have without issue as long as they don't use the wmi module.
I looked at the win32com _init__.py line 5 where it's messing up and it's just an import statement for win32api.
System:
Windows 7 x64, Python 3.5.3 64bit, Anaconda 4.3.14 64bit, using pyinstaller 3.2.3 (recommended by this thread), with pywin32 220 (with sourceforge download [I know, I tried pip, conda, and easy_install]) and I'm running it in cmder as an admin.
In my case, I couldn't use the module in the python shell, even if original one could. When I execute python shell as an administrator option, it was solved. Try it with administrator execution. I used python version 3.5.2 with windows x64bits.
I face this problem but I install ---> pip install pypiwin32 to solve my problems

Resources