Unable to import libraries in Python - python

Yesterday, I accidentally deleted the Path variable but I think I restored them. I added Python path to it and I've got my python running through command prompt and also pip is working. However, I'm unable to import new modules to Python shell.
It comes up with the following error
enter code here
File "<pyshell#1>", line 1, in <module>
import wxPython
ModuleNotFoundError: No module named 'wxPython'
Any suggestions as to what I'm missing? Maybe I didn't add the Path correctly?
here is what I have added
%SystemRoot%\system32;
%SystemRoot%;
%SystemRoot%\System32\Wbem;
%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Common Files\Oracle\Java\javapath;
C:\Users\user1\AppData\Local\Programs\Python\Python36-32\Scripts;
C:\Users\user1\AppData\Local\Programs\Python\Python36-32;
C:\Users\user1\AppData\Local\Programs\Python

Also add C:\Users\<your user>\AppData\Local\Programs\Python\Python36-32\Libs; to your path

Related

Import Arcpy Module Failing - PyScripter

I am trying to use PyScripter however I can import certain modules however I am unable to successfully import the arcpy library.
I have tried configuring the Environment Variables PYTHONPATH without any success. I know I'm missing something with the the correct path to the python executable.
Thanks for your assistance in advance
The Desktop10.8pth references the following
C:\Program Files (x86)\ArcGIS\Desktop10.8\bin
C:\Program Files (x86)\ArcGIS\Desktop10.8\ArcPy
C:\Program Files (x86)\ArcGIS\Desktop10.8\ArcToolBox\Scripts
Pyscripter is returning the following
import arcpy
ModuleNotFoundError: No module named 'arcpy'
IDLE Shell is returning
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import arcpy
ModuleNotFoundError: No module named 'arcpy'
Enviromental Varibles
Program Files 86 to ArcGIS
Pyscripter Path
Pyscripter Path Additional
Python Structure
Python27
The message ModuleNotFoundError: No module named 'arcpy' comes from whatever pythonx.y you are running. Do you have more than one python installed on your system? If so, the common error is to install something for one python and try to import it with another.
What you call the 2.7 structure shows Python39-32. Does arcpy run with that version?
If you are trying to run arcpy with python x.y, the pythonx.y directory Lib/site-packages/ must contain the arcpy package or a .pth file pointing to its location. Is Desktop10.8pth a typo version of Desktop10.8.pth. If so, then one of the directories, most likely the one ending in ArcPy must contain either an arcpy package directory or an arcpy.py file.

DLL load failed, module not found?

I have a folder with a file "main.py" and a file "_test.pyd" (note .pyd). The file "main.py" looks like this:
import _test
I get the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import _test
ImportError: DLL load failed while importing _test: The specified module could not be found.
Why is this error coming up? Cheers.
Note: I was given this code by others, and it works for the original authors, so I'm not sure what's wrong with me/my machine.
Update: Running os.path.isfile('_test.pyd') returns True, so I don't think it's a problem with the path
You should append the path of the folder which contains the imported module before import.
Code:
import os
import sys
sys.path.append(os.path.realpath(os.path.dirname(__file__)))
import _test # noqa: E402
EDIT:
Other ideas:
Adding __init__.py file to the related director.
Checking the PyInit_foo() function in .pyd file.
If the Python finds the .pyd file, it will attempt to call PyInit_foo() to initialize it
Update Following posts from people experiencing similar issues, I tried downgrading my Python version (from 3.8.4rc1 to 3.5.4) and the import now works correctly. No clue why. I guess the .pyd file was written in that version of Python (I'm not the author of the file), but still I'm clueless as to what the exact origin of the problem is.
I've been through this error and what I found after a lot of investigation:-
issue was in Opencv==4.5.1 build from source with cuda and flag cuda_with_fast_math=on
I just rebuild OpenCV and disable
cuda_with_fast_math
and it works for me.

How to import my python file in another file in visual studio code

I am using python/selenium in visual studio code. I am trying to import my another python class driverScript which resides in executionEngine module and in the file DriverScript. I have imported as below:
import driverScript from executionEngine.DriverScript
It is producing error:
Traceback (most recent call last):
File "c:/Selenium/Selenium-Python Framework/RK_Practice/Tests/mainTest.py", line 5, in <module>
from executionEngine.DriverScript import driverScript
ModuleNotFoundError: No module named 'executionEngine'
How can I import correctly? Your help is very much appreciated.
If the script you are wishing to import is not in the current directory, you may want to take this approach:
import sys
sys.path.insert(1, '/path/to/script/folder')
import driverScript from executionEngine.DriverScript
If your python file is on the same level in dir, then you can import just by calling:
import filename
If your python file is inside another folder, then you need to create a blank __init__.py file that will help python to understand it's a package. Then you can import that as follows:
from folderName import filename
Depends on where executionEngine is supposed to come from. If it's from a package installable via a package manager such as pip or Anaconda, looks like it's not properly installed. If you installed it yourself, you probably need to add the directory containing executionEngine to your PYTHONPATH, so the Python interpreter can find it. This can be done in the VSCode environment files. See the PYTHONPATH section in https://code.visualstudio.com/docs/python/environments

I got an error when calling kmodes module in python

When calling the kmodes package like this:
# I have also tried
# from kmodes.kmodes import KModes
from kmodes.kprototypes import KPrototypes
ModuleNotFoundError: No module named 'kmodes'
As suggested by #648trindade, all I had to do was install the package. That's not included in Anaconda by default.
I had same issue. It turned out that I named my test file as kmodes.py, and current directory is in sys.path. so python use my test file as the library.
If you have set the system path to some folder having kmodes.py file, just rename your script as something else, everything is fine.
Or you just remove the sys.path line from the code and restart the compiler

I have 32 bit python and 32 bit WMI module installed but wmi returns an error

I installed wmi with the installer here http://timgolden.me.uk/python/wmi/index.html
but I can't get the module to import.
Here is my code:
import wmi
c=wmi.WMI()
for os in c.Win32_OperatingSystem():
print(os.Caption)
and here is the error:
Traceback (most recent call last):
File "C:/Python33/Programs/WMI trial.py", line 1, in <module>
import wmi
File "C:\Python33\lib\site-packages\wmi.py", line 88, in <module>
from win32com.client import GetObject, Dispatch
ImportError: No module named 'win32com'
Any idea why this isn't working? I have a 64 bit system but that hasn't affected running 32 bit python at all.
Any help is greatly appreciated!
you are missing the 'Python For Windows Extensions' (pywin32).
WMI module requires pywin32.
run the appropriate installer for pywin32, then try WMI again.
The "No module named 'win32com'" error is because it can't find the winm32com module (which is installed as part of pywin32 package.)
What worked for me is:
i downloaded the source named: WMI-1.4.9.zip from https://pypi.python.org/pypi/WMI/
Extracted all files from that zip file and saved it in a folder named: WMI-1.4.9 and then copied that folder to C:\Python27\Lib\site-packages.
After that I navigated to that folder C:\Python27\Lib\site-packages\WMI-1.4.9 and did a shift + right click -> Open Command line here and ran: python setup.py install
That's it, after that it worked for me like charm. No issues.
p.s - While installing exe I had some weird Access Denied errors, I tried by running the exe as Administrator even then I could get through it. Hence that didn't at all work for me.
Edit:
Also I had pywin32 installed from here:
http://sourceforge.net/projects/pywin32/files/ (select the correct file - 'bittedness' and python version wise)

Categories

Resources