Python module not found when using MSIPred - python

I am very new to python. I am trying to use a pre-existing algorithm on my data:
https://github.com/wangc29/MSIpred
I downloaded the code from GitHub and used my command line installer as suggested on the first instruction of the vignette in the above link.
I save a python file in the same directory as the downloaded code and attempt to execute the first line:
import MSIpred as mp
I receive this error:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import MSIpred as mp
ImportError: No module named MSIpred
This is my directory organization. I have tried with both MSI_Smoker and MSI_Smoker2 as seen in the image below.
Any suggestions?
Edit:
In response to some comment, I tried moving the python script into the parent folder but I get the same error.

The easiest way is to add the lib path to the environment parameter PYTHONPATH(https://www.tutorialspoint.com/What-is-PYTHONPATH-environment-variable-in-Python)
export PYTHONPATH=$PYTHONPATH:`pwd` (replace `pwd` to the lib path)
link Python error "ImportError: No module named"

Related

Folder being mistaken for module Error: no module named "GAN"

I'm running this github project: https://github.com/Biomatter-Designs/ProteinGAN
the second step says 2. Run the training script with python train_gan. but when I run the file I get:
/usr/local/bin/python3 /Users/user/Desktop/ProteinGAN-master/src/gan/train_gan.py
Traceback (most recent call last):
File "/Users/user/Desktop/ProteinGAN-master/src/gan/train_gan.py", line 8, in <module>
from gan.models import get_model, get_specific_hooks
ModuleNotFoundError: No module named 'gan'
I don't understand why it thinks the GAN folder is a module.
Had the issue error trying to import gan files on google colab.
I corrected my /content/gdrive folder to the exact path and it worked.
I hope this helps out.

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.

unresolved import 'GUI.py' Python(unresolved-import) when importing functions from code in same directory

I'm trying to call functions from separate python files within the same folder directory but receiving the following error within VSCode.
unresolved import 'IXL_main.py'Python(unresolved-import)
When trying to run the code directly I get the following error:
Traceback (most recent call last):
File "TMS_main.py", line 30, in <module>
from TMS_threading import globalStopAllTrains
ImportError: cannot import name 'globalStopAllTrains' from 'TMS_threading' (C:\Users\....\TMS_threading.py)
I've tried the following:
Refresh VSCode
Refresh & Check Python Interpreter
Reinstalling VSCode
Re-Typing Import Modules & Files
Creating and adding .env file and path to settings.json
I need more information.
So you have two files in the same folder. You run the first file with Python (python first_file.py). This first_file imports the second one like this:
from second_file import your_function. Then, still in your first file, the command your_function(arguments) raises this error ?
Search 'jedi' in the settings to replace Microsoft Python Analysis Engine

paraview-python: Could not import vtkCommonComputationalGeometry

I try to run a python script (test.py) containing this line only:
from paraview.simple import *
I want to use the last version of paraview. So, I downloaded it from the official webpage and I uncompressed the corresponding archive into a folder, say /home/paraview.
If I do not anything more than running the script with
python test.py
I get the following error message:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from paraview.simple import *
ModuleNotFoundError: No module named 'paraview'
So, I set my PYTHONPATH like this:
export PYTHONPATH=/home/paraview/lib/python2.7/site-packages:$PYTHONPATH
Then, I rerun my script and I get a different error message:
Error: Could not import vtkCommonComputationalGeometry
Segmentation fault
I tried to set LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/home/paraview/lib
where vtkCommonComputationalGeometry.so is but it does not work.
Furthermore, if I try to locate vtkCommonComputationalGeometry, I find it in another location:
/usr/lib/x86_64-linux-gnu/libvtkCommonComputationalGeometry-6.2.so
I removed vtk with apt but it is still here.
Do you know how I could run my script?
Just use pvpython, that can be found in ParaView binaries.
path/to/ParaView/bin/pvpython test.py
try to install PVGeo package.
pip install PVGeo

ModuleNotFoundError: No module named 'bayesnet'

I'm trying to use the OpenBayes module, but the problems start from the very first step :'(
When I try to import from OpenBayes
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Мари\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenBayes\__init__.py", line 7, in <module>
from bayesnet import *
ModuleNotFoundError: No module named 'bayesnet'
UPD: While installing (from .exe file) for py2 i gor error: "could not set a key value" (not a python error, but in dialog window)
I tried using pip install from console, but still get errors there.
Command "python setup.py egg_info" failed with error code 1 in C:\Users\CD3B~1\AppData\Local\Temp\pip-build-m4nnwa4o\OpenBayes\
Also not sure which py (2 or 3) is used when i type a command from console(
(Sorry for all that stupis questions)
You should
from OpenBayes import *
or
from OpenBayes import BNet
Here is an example demonstrating it's usage:
https://github.com/willasaywhat/OpenBayes-Fork/blob/master/Examples/bn_asia.py
I had the same problem and I created a directory with the same name as the root folder (within the root folder). Python then referred Its import calls to the src directory and not the folder. I also changed the python interpreter to a virtual (anaconda.exe), as the python install did not contain many of the modules that were being called by the application (flask, etc)
It's a weird workaround, but it worked for me. Hope this helps

Categories

Resources