I'm working on linux ubuntu 20.04. I opened new python project using Pycharm IDE, and I've installed a package called aihwkit, the documentation and the source.
When running the examples given with the source code, which use modules imported from a directory called inference such as example 06_lenet5_hardware_aware.py I'm getting an error:
ModuleNotFoundError: No module named 'aihwkit.inference'
although other folders, in the same directory as inference are imported as well and they work well. I'm trying to import this manually, but not sure how to do it.
This is the hierarchy of the folders: I'm calling inference like this:
from aihwkit.inference import PCMLikeNoiseModel
from the file examples/06_lenet5_hardware_aware.py when the module PCMLikeNoiseModel source code lies in the following path: src/aihwkit/inference/noise/pcm.py
please note that the problem is that the name aihwkit.inference is not found, while other names such as aihwkit.nn do not raise any error, and they reside in similar path to inference.
I'm adding a picture of the hierarchy in case it helps:
how can I import this folder manually?
Thank you
Since you're on Linux, you can try to install your package before importing it with:
sudo apt-get install python-#name_of_your_package
written in your terminal, or you can try to install it with pip
Related
I'm running a code on deep learning, which uses the opencv module, by running python main.py (contains import cv2 statement), but always get the error 'ImportError: dynamic module does not define module export function (PyInit_cv2)'.
I've tried to reinstall my anaconda and create new virtual environments, but all got the same result. This problem really confuses me a lot and I've googled for many related problems, none of them works. I think the problem is something related to the environment and has nothing to do with the code, because I got the same result by simply run import cv2 in python prompt. The more confusing thing is that, even after I remove the opencv module, I also get the same problem, but not a ModuleNotFoundError. Does anyone can give me some advice? Thanks a lot!
I think I found one possible reason of this error.
Recently I was configuring the caffe environment on one server, I downloaded the source code of opencv-2.4.13 and compiled manually, added /usr/local/opencv-2.4.13/build/lib to $PYTHONPATH, and caffe worked well. After that, when I entered one of my virtual environment using conda activate py35, which uses python3.5, tried import cv2 in the python prompt, got the error above.
I'm not sure but I think the cause of the error is opencv-2.4.13 compiles a python2 interface so it can't be imported by python3. Python imports packages by searching the directories listed in sys.path, where $PYTHONPATH is in the second place after the current working directory (This is a great article introduces the mechanism of python finding packages). So when we enter the py35 environment, python will first look for $PYTHONPATH and find the opencv installed on the root directory instead of finding the opencv in the virtual environment using conda install opencv-python.
So there are two solutions of this problem:
Use python2 instead.
Remove /usr/local/opencv-2.4.13/build/lib from $PYTHONPATH.
which all work for me.
Similar post, might help:
ImportError: dynamic module does not define init function (initfizzbuzz)
Could you provide info on how you installed the CV module?
I had the same problem, which was caused by the cv2.so file in /usr/local/lib/python2.7/site-packages/cv2.so. After I deleted the file and use command sudo pip3 install opencv-python, it worked for python3.
I installed meshpy (using python 2.7) following the instructions here on my ubuntu 16.04 LTS and trying to run examples from here after browsing into the directory of meshpy. Part of the example that I'm trying to run is below:
from __future__ import division
from __future__ import absolute_import
import meshpy.triangle as triangle
but I keep getting error No module named meshpy._triangle
Does anyone have a hint of what I might be missing ?
Likely you have created file named meshpy within your python package, which leads to the module shadowing, renaming your file shall fix the problem.
See more by next links:
The name shadowing trap
Python: Problem with local modules shadowing global modules
After an entire day of labor I realized the python packages that I had were not correct and causing conflicts. To begin with here is the link to the installation documentation of meshpy which I followed Here is a pointwise summary of what I realized caused problem
Step 1 says download the file, unzip it using the command given in the doc, and browse to the directory 'MeshPy-XXXXX', where 'XXXXX' refers to the version.
The issue in this step is that a file called CMakeList.txt is missing in this directory and while configuring in step 2 the system complains about the missing file.
The solution is to download the git version instead of the direct download as mentioned in the second part of step1 or manually copy the file CMakeList.txt into the MeshPy-XXXXX directory. I chose the latter solution.
In step 2 asks us to browse to the directory and issue the command ./configure on the terminal. This didn't work for me. The directory contains a script called configure.py . Hence instead I issued python3.5 configure.py
If you issue python configure.py and python calling python2.7 then you should make sure python2.7 has matplotlib, numpy installed as meshpy depends on these packages
The last of step2 where you need to issue command python setup.py install is a tricky part where things went crazy for me. Firstly, I issued python setup.py but what I should have done is issuing python3.5 setup.py (or better creating an alias to python3.5 in bash).
When I pinned down the mistake, I started getting another error both with python2.7 and python3.5, last three lines of which looks like below :
bpl-subset/bpl_subset/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
When I looked up stackoverflow for possible similar errors, I came across this article and used the second solution in the post and installed python2.7-dev/python3.5-dev which solved the problem .
Go to the installation page and click on 'Download MeshPy' link. Click on 'Download Files'. Download the tar file. Unzip it. Then copy the 'meshpy' folder and paste it inside your python lib directory where other packages are stored. Hope it will solve the problem.
I'm trying to follow the tutorial at https://www.juliensobczak.com/tell/2016/12/26/anki-scripting.html
And I'm getting the "listcards.py" basic script set up, having cloned anki and installed the virtual environment as well as the requirements from the anki/requirements.txt file.
However, when I run the script from the tutorial entitled "listcards.py", I get a notice that the module 'anki.sched' is not found. ("ModuleNotFoundError: No module named 'anki.sched')
While I could pip install each package, I have a feeling that there must be an underlying reason that these packages are missing- is there a way to have python automatically pull in the named module even if it isn't pre-installed in the manner of how node.js installed referenced dependencies automatically, so that I won't have to manually install every missing package?
I ran into this same problem. anki.sched is a package contained within the anki repository you cloned, so it does exist on your machine. You won't be able to install it using pip.
The solution for me was to write the absolute path of the anki repository you cloned in sys.path.append rather than a relative path. For example, if your script exists in /Users/anki/scripts and your cloned anki repository exists in /Users/anki/anki write this in your script before importing anki modules:
sys.path.append("/Users/anki/anki")
rather than this (which is what is provided in the tutorial):
sys.path.append("../anki")
I'm not 100% sure why the latter fails, but Anki must be looking for the anki.sched module in the wrong place due to the relative reference.
What I did, and I know this is probably not the correct way, is to simply wipe out the root anki folder and copy all the application scripts to it, then the imports worked.
I tried to load the movie_lens dataset using the code below
from lightfm.datasets import fetch_movielens
running this i am getting:
ImportError: No module named 'lightfm.datasets'; 'lightfm' is not a package
It sounds like the lightfm package is not installed in your environment. You can check in File>Project Structure>SDKs make sure lightfm is present in the Packages tab of the environment you're using for your project. Otherwise you can add the package from that same window.
since i have already tried many ways and failed,finally i run my python terminal from the default python3.5 saved folder -->for me it is /usr/bin ,then i created a new project in pycharm IDE ,istalled lightfm using pip3 it worked there too ,now i can import LightFM
I'm trying to install PyDrive [a wrapper library of the google drive api for python] and pip is giving me this error. It did the same thing when trying to install things like matplotlib or mega.py [a mega.nz api for python].
Here's the error:
Anyone got a clue what's going on?
Cheers
You could try renaming that pip.py to something else.
There is a library called pip somewhere on your system (and it may also be bundled within pip.exe). That is different from the "entry point" script that actually runs pip from the command line. When you run pip, it will try to import the library called pip. If there is a script called pip.py in the Scripts directory (representing the entry-point script, not the library), it may import that instead of the real library. If this is indeed the problem, renaming pip.py to something else will remove the name conflict and allow pip to properly import the library it needs.
I'm not sure how you wound up with pip.py in your Scripts directory in the first place. I don't think it should be there. My Python installation on Windows doesn't have it.