Import Arcpy Module Failing - PyScripter - python

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.

Related

Anaconda cannot find package dependencies, cmd python can

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?

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

No module named 'azure.eventhub'; 'azure' is not a package

I am trying to execute this example using Python 3.7 with Pycharm and azure-eventhub 1.2.0 package.
When I try to run it, I get this error:
ModuleNotFoundError: No module named 'azure.eventhub'; 'azure' is not a package
This is the problematic line:
from azure.eventhub import EventHubClient, Receiver, Offset
What could be happening?
This is my project interpreter
Using pip freeze:
As I known, there is a case which will cause your issue.
The Python Interpreter searches the available packages, objects and methods in the paths of sys.path in order, you can print the value of the sys.path variable to see the order after import sys.
So if there is a Python script named azure.py prior to the real azure package, you will get the issue ModuleNotFoundError: No module named 'azure.eventhub'; 'azure' is not a package.
Here is my steps to reproduce this issue.
I created a Python script named azure.py in the current path which only have one line code print('pseudo azure package').
Then, I opened my Python interpreter in the current path and type from azure.eventhub import EventHubClient, Receiver, Offset, then to get the issue as below.
It also will happen in Pycharm, even using virtualenv, please check whether exists a file called azure.py or azure.pyc in your current path or the paths in the order of sys.path list.

Unable to import libraries in 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

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