I am trying to import a python module from a certain folder. This is the code:
import sys
sys.path.append(r"C:\path\to\module_foobar")
import foobar
In a miniconda env with all prerequisites installed (python 3.10 and numpy), I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed while importing foobar: The specified procedure could not be found.
But with the system python in cmd, the same code works.
Tried adding the path to system path variable as well as specifying it in a custom .pth file in the site-packages folder of the miniconda environment.
Tried running dependencywalker on the .pyd file of the package and it says that a bunch of MS C++ Redistributeable dll files seem to be missing. Tried repairing those to no avail.
What on earth could be wrong?
Related
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.
I'm trying to run a Python script from the Windows shell, but when I do
python path\to\file\script.py
I get an error "DLL load failed: The specified module could not be found" and it traces back to the line where I import numpy.
C:\Users\Admin>python path\to\file\script.py
Traceback (most recent call last):
File "path\to\file\script.py", line 8, in <module>
import numpy as np
File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\Admin\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
The weird part is that when I run it in an editor like Spyder, numpy imports just fine. Can someone help me?
Thanks
It's fixed Anaconda path issue. Check your %PATH% if it's correctly defined.
Source: https://github.com/numpy/numpy/issues/12957
This is a common problem when installing python packages, mainly in windows.
Numpy and other packages have bindings to C++ code that require some special dependencies.
Rather than trying to get the dependencies exactly right for compiling the package, you can use a precompiled "wheel" file from one of several sources.
I use Chris Gholke's site
download the .whl file and install using
pip install directory/path/package.whl
edit: and as a note, the python environment you access from powershell or cmd is different from the anaconda environment in spyder. One of the differences between conda and pip is that conda installed precompiled packages while pip does not.
I solved my issues with Numpy DLL load issues by replacing Anaconda3 with WinPython.
I need to use M2Crypto in my python script. I downloaded the M2Crypto windows installer from: https://pypi.python.org/pypi/M2CryptoWin64
When I imported the M2Crypto in my script using: import M2Crypto and run my script, I get errors.
Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/TLSscanner/scanner_v2.py", line 4, in <module>
from M2Crypto.Err import SSLError
File "C:\Users\xxx\PycharmProjects\TLSscanner\M2Crypto\__init__.py", line 22, in <module>
import __m2crypto
ImportError: No module named '__m2crypto'
I do not know where to place the M2Crypto folder after I installed it and extracted it? Can you clarify to me where packages need to be placed in order for the script to run?
EDIT:
This is the successful installation path. Shall I put my python script in the same path? The error I get when running my script (in another folder for the project) is shown above.
Im a trying to build a COM server in Python. I have downloaded and installed Pywin32 (I use 32-bit version of Python 3.4.1, so I downloaded and installed pywin32 for this version).
Now, in order to import pythoncom in IDLE, I need to have two .dll files readily accessible:
-pythoncom.dll
-pywintypes.dll
Both .dll files are in the following directory:
C:\Python34\Lib\site-packages\pywin32_system32
When I give the import statement in IDLE, I get the following error:
Traceback (most recent call last):
File "", line 1, in
import pythoncom
File "C:\Python34\lib\site-packages\pythoncom.py", line 2, in
import pywintypes
ImportError: No module named 'pywintypes'
I reinstalled pywin32, but it still doesn't fix it.
I am now trying to add C:\Python34\Lib\site-packages\pywin32_system32 to my PATH directory, but it doesn’t work. I am trying this via:
os.environ["PATH"] += os.pathsep + C:\Python34\Lib\site-packages\pywin32_system32
I then get the following message:
The syntax of the command is incorrect.
What error am I making in the syntax above? How can I fix this (i.e. how can I add C:\Python34\lib\site-packages\pythoncom.py to my PATH environment)?
When I try to import the slycot module in spyder (version 2.2), I get the following error:
RuntimeError: module compiled against API version 7 but this version of numpy is 6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/__init__.py",
line 4, in <module>
from slycot.analysis import ab01nd,ab05md,ab05nd,ab07nd,ab08nd, ab09ad
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/slycot/analysis.py",
line 21, in <module>
from slycot import _wrapper
ImportError: numpy.core.multiarray failed to import
Now, when I import slycot in the python shell through my terminal, there are no problems at all. I think the reason why there are no problems through the terminal, is that I recently installed numpy 1.7.1. Spyder on the other hand still uses numpy 1.6.2.,hence the error.
I tried to change the numpy version in spyder, but so far that didn't work.
When I change the numpy(6) folder in my spyder lib with the recently installed numpy(7), I get the following error (in spyder):
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
What is the best way to solve this error?
Thanks in advance.
(Spyder dev here) At the moment it's not possible for the user to install anything inside the app. I guess you moved your slycot module from another interpreter to our App (because of the numpy error you mention).
The right way to use different modules not present in the app, is to change the path of your interpreter in:
Tools > Preferences > Console > Advanced settings > Python executable
If you installed slycot using your system Python, you have to select
/usr/bin/python