Cannot load .pyd module in Python - python

I am writing a workflow in Jupyter that uses some C code which has already been compiled to a .so file (for Linux, where everything works fine) and a .pyd file (for Windows, which I am using). The import tree is a little complicated, so bear with me. The error message hopefully explains it:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-9-cabd8b5ab266> in <module>
12 import plotly.graph_objects as go
13
---> 14 from lase_analysis import load_lasefile, load_timeseries
C:/Users/Owner/.../v2\lase_analysis\__init__.py in <module>
2 from .spectrum import Spectrum
3 from .threshold import Threshold
----> 4 from .lasemap import LaseMap
5 from .laseseries import LaseSeries
6 from .readermatl import ReaderMATL
C:/Users/Owner/.../v2\lase_analysis\lasemap.py in <module>
14 from .filelase import FileLase
15 from .spectrum import Spectrum, PeakFitOpt
---> 16 from .utils.c_funcs import clst_dist
17
18
ImportError: DLL load failed while importing c_funcs: The specified module could not be found.
Basically, in the Jupyter session, I am importing __init__.py from the folder lase_analysis (the first arrow in the error message), which imports a class LaseMap from the file lasemap.py. Then, this lasemap.py file tries to open a C function clst_dist from the file c_funcs.pyd, which is located in a folder called utils which is in this same folder lase_analysis that all of the previously mentioned Python files are located in. However, I still get the error that the .dll file (which should be equivalent to a .pyd file here) cannot be found.
Any help would be appreciated, and my apologies if this was a bit hard to follow.

Related

ImportError: cannot import name 'string_int_label_map_pb2' On windows

I am attempting to use the tensorflow object classifier and am having some slight issues when it comes to importing the models.
I am following a tutorial (https://gilberttanner.com/blog/installing-the-tensorflow-object-detection-api) and from what I seen on google alot of others have had similar issues regarding the import.
Having downloaded TensorFlow/models, pycocotools, I have then installed protobuf, I managed to run it and convert the PROTO files to Python Source file - I thought I was on the home stretch here.
But when running through the object_detector tutorial I get so far before I run into this importerror
---------------------------------------------------------------------------
`ImportError Traceback (most recent call last)
<ipython-input-10-962ae4a715f3> in <module>
1 from object_detection.utils import ops as utils_ops
----> 2 from object_detection.utils import label_map_util
3 from object_detection.utils import visualization_utils as vis_util
4 from protos import string_int_label_map_pb2
c:\users\robert\appdata\local\programs\python\python38\lib\site-packages\object_detection\utils\label_map_util.py in <module>
19 import tensorflow as tf
20 from google.protobuf import text_format
---> 21 from object_detection.protos import string_int_label_map_pb2
22
23 enter code here`
ImportError: cannot import name 'string_int_label_map_pb2' from 'object_detection.protos'
(c:\users\robert\appdata\local\programs\python\python38\lib\site-packages\object_detection\protos\__init__.py)
I am a bit confused here - Maybe I stared at this for a bit too long..-
I can go into the files and within object_detection/protos there is a string_int_label_map_pb2
So whats going wrong?
I have looked at alot of other posted similar to this but I cannot seem to find an exact answer for what I need. I have set the pythonpath, ran python setup.py build & install. But I am stuck.
I am still new to all this, and Im sure I am being really dense and missing something obvious. But any help would be amazing.
Thank you

How to import modules from py files

So I received three python files with some functions. It's an util library provided by a third party. When I want to import these in my python file I use this code (as was specified by the third party):
import util.submission as S
import util.vis as V
import util.metrics as M
But then I get this error. I am working in Google Colaboraty and I uploaded the three python files in my current working directory on google colab so I don't understand. How do I fix this? The three files are just named submission.py ; vis.py and metrics.py. Any help here? This should be quite basic but it doesn't seem to work.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-1e1451b5bba0> in <module>()
1
----> 2 import util.submission as S
3 import util.vis as V
4 import util.metrics as M
ModuleNotFoundError: No module named 'util'
Create a folder in your current working directory named utils, and place the three .py files inside of it. You can then use the import statements as you have specified.
https://realpython.com/absolute-vs-relative-python-imports/#syntax-and-practical-examples

How to add python library to Spyder

I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:
Adding library path containing .py files to Tools>PYTHONPATH manager
Synchronizing the path
Updating module names list through Tools>Update Module names list
However, when I try to import modules from this library I get two types of errors:
import easy
Traceback (most recent call last):
File "<ipython-input-2-685519d35f15>", line 1, in <module>
import easy
File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
from .server import Server, InputProcessor
ValueError: Attempted relative import in non-package
The second type of error as follows:
from plxscripting.easy import *
Traceback (most recent call last):
File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
from plxscripting.easy import *
ImportError: No module named plxscripting.easy
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?

How can I import 2 module in Python?

Guys I'm new in Python and I'm trying to understand modules.I have a folder in desktop and there are 2 module in that folder. One of them is pr.py ,it's takes a array and displays it.And other one is fillArray.py.Now I want to add these 2 friend into interpreter but when I used in interpreter import pr.py or import fillArray it's giving to me this error
>>> import pr
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pr
ImportError: No module named pr
Then if I clicked f5(run) in pr.py module ,write again in interpreter import pr it works.That's ok.But trying to run fillArray.py module same steps, it's restart interpreter and it works butpr.py module is removing.How can I handle this?By the way this can be unnecessary but I'm using python2.7.
Edit:I wrote print.py sorry it should be pr.py
If you have both the modules in the same folder, you can use . which specifies current directory as follows:
from .pr import *
This statement will import all functions of print.py which is in the current directory
If you want specific things to be imported, just specify using their names
from .pr import myfunc1, myfunc2, myclass1, myclass2
If you wish to import the whole module, use:
from . import pr
Hope this helps :)

Strange Python Import Error

I am new to Python. I am getting ImportError and seem to have tried everything that's in the documentation and the various notes in this site and other
My code is structured as follows:
vsm
|
|______bin
| vsmx.py
|______site-packages
__init__.py
|
|_____libs
__init__.py
monitor.py
In monitor.py I have a function named getStr and the two __init__.py files are empty
I have the PYTHONPATH set to vsm/site-packages & vsm/site-packages/libs. When I run from command line, python bin/vsmx.py, I get:
Traceback (most recent call last):
File "bin/vsmx.py", line 15, in <module>
from libs.monitor import getStr
File "/var/src/vsm/bin/vsmx.py", line 15, in <module>
from libs.monitor import getStr
ImportError: No module named monitor
However, when I try to run this interactively, it seems to work. I tried on both windows and linux using python 2.6.1.
Any pointers will be much appreciated
ImportError: No module... is usually a very (obscure) error meaning that you have circular imports.
Module a.py:
import b
Module b.py:
import a
Then main.py:
import a
This should cause ImportError: No module named a, because a is importing b and not ready when b tries to import it.

Categories