Python script ImportError: No module named celltool.simple_interface - python

so I'm on a Windows 8 and I'm doing some image analysis for my research. It requires running this python script (I did not write it) called "calculate_distances.py". I am also using CellTool (http://pantheon.yale.edu/~zp2/Celltool/) and Numpy which I have successfully installed.
When I try to run my calculate_distances script, I get this error:
Traceback (most recent call last):
file "calculate_distances.py" line 4, in <module>
import celltool.simple_interface as si
ImportError: No module named celltool.simple_interface
Here is my calculate_distances.py script:
#!/Library/Frameworks/Python.framework/Versions/2.5/bin/python
# Import various celltool modules
import celltool.simple_interface as si
import celltool.contour.contour_class as contour_class
from celltool.utility.path import path
import celltool.utility.datafile as datafile
import numpy
# Designate your working directory - ie, replace '/parent_directory/' with the path that contains your contour files
#parent_dir=path('/parent_directory/')
parent_dir=path('./')
# Identify and load all of the contour files
contour_files=parent_dir.files('*.contour')
contours=si.load_contours(contour_files)
all_distances=numpy.arange(len(contours[0].points))
# Calculate the normal displacement of the cell boundary at every contour point.
n=1
while n<len(contours):
contour_class.Contour.global_reorder_points(contours[n],contours[n-1])
displacement_vectors = contours[n-1].points - contours[n].points
normals = contours[n-1].inward_normals()
distances = (normals * displacement_vectors).sum(axis=1)
all_distances=numpy.vstack((all_distances,distances))
n=n+1
# Save a csv file with the normal displacement of the boundary at each contour point (columns) at each time point (rows)
datafile.write_data_file(all_distances,parent_dir/'distances.csv')
I have no idea what the error means, as I'm a first-time programmer. First I thought I needed to install a C++/fortran compiler, so I installed Simple Fortran, but it still does not work. Everything works fine on Mac system (after I installed GNU fortran) but for some reason it's not working on Windows. Is it because my CellTool is not installed in the right location? Or is it something with the script?
Any ideas? Thanks very much for your help!!

You have two options then.
Try adding CellTool installation directory to your PYTHONPATH environment variable, if you haven't already (create this variable if necessary).
Search for something like celltool.dll or libcelltool.dll (or even celltool.py). See if it helps. If not :
Compile the source by following those few steps... Install MinGW (installer here), checking C/C++ (gcc/g++) and Fortran when asked by the installer. Then add C:/MinGW/bin (or whereever you installed MinGW) to your PATH environment variable. Download and unpack CellTool source package from the web site. Finally open a command shell (search for cmd program), change directory to the newly unpacked directory and build by typing :
python setup.py install
This should properly compile and install the celltool python package to the site-packages directory of your Python installation.
Option 2 is the sure/safe (but not easiest, I agree) way to get it work.

Related

Pandas Installed For All Python Versions But Module Can't Be Found

I am trying to modify an AI for a game on the steam store. The AI communicates through the game with the use of a mod called the communication mod. The AI is made using a python project. The package I am trying to modify is https://github.com/ForgottenArbiter/spirecomm and the mod is https://github.com/ForgottenArbiter/CommunicationMod.
I want to add the pandas package and the job lib package as imports so I can use a model I have made for the AI. When I try to run the game + mod after adding the pandas and joblib packages as imports I get this error in the error log.
Traceback (most recent call last):
File "/Users/ross/downloads/spirecomm-master/main.py", line 6, in <module>
from spirecomm.ai.agent import SimpleAgent
File "/Users/ross/Downloads/spirecomm-master/spirecomm/ai/agent.py", line 10, in <module>
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
This issue only happens when the game is running and the mod tries to run. if I just run the file in terminal it is able to compile/run and send the ready signal
I have checked that I have these modules installed and it is installed. I am on an M1 Mac and I have several different versions of python installed but I have checked them all and it is installed for each of them. I have also opened the python package using pycharm and added pandas and joblib to the python interpreter as a package.
Another thing I have tried is modifying the setup.py file to say that pandas and joblib are required. I then ran it again but I am not sure if this had any effect because I have already run it before.
There is limited help that can be provided without knowing the framework that you are is using but hopefully this will give you some starting points to help.
If you are getting a "No module named 'pandas'" error, it is because you have imported pandas in your code but your python interpreter cannot find it. There are two major reasons this will happen, either it is not installed (which you say has definitely happened) or it is not in the location the interpreter expects (most likely).
The first thing you can do is make sure the pandas install is in the PYTHONPATH. To do this look at Permanently add a directory to PYTHONPATH?.
Secondly, you say you have several versions of python and have installed the module for all versions but you most likely have several instances of at least one version. Many IDEs, such as PyCharm, create a virtual environment when you create a new project and place in it a new instance of python interpreter, or more accurately a link to one version of python. Within this virtual environment, the IDE then loads the modules it has been told to load and thus makes them available for import to the code using that particular environment.
In your case I suspect you may be using a virtual environment that has not had pandas loaded into it. You need to investigate your IDEs documentation if you do not know how to load it. Alternatively you can instruct the IDE to use a different virtual environment (one that does have pandas loaded) - again search documentation for how to do this.
Finally, if all else fails, you can specifically tell your code where to look for the module using the sys.path.append command in your code.
import sys
sys.path.append('/your/pandas/module/path')
import pandas

Unable to import Pandas on Replit.com - Python

I'm unable to import pandas with import pandas as pd on replit.
I've already installed the package with pip install pandas and it can be seen in packages. I've successfully imported it to other projects on replit. Every time I try importing it into my code on this project, it gives me the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import pandas as pd
File "/home/runner/thing/venv/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/home/runner/thing/venv/bin/python"
* The NumPy version is: "1.22.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: libz.so.1: cannot open shared object file: No such file or directory
You don't need to use pip to install packages on repl.it -- and in fact, you shouldn't! Using Nix derivations not only works better (as you're using their OS distro the way it's designed), but also keeps their storage costs low, by allowing packages to be used from a read-only, hash-addressed, shared store.
Binaries built for other distributions might assume that there will be libraries in /lib, /usr/lib, or the like, but that's not how NixOS works: Libraries will be in a path like /nix/store/<hash>-<packagename>-<version>/lib, and those paths get embedded into the executables that use those libraries.
The easiest thing to do here is to create a new bash repl, but to add a Python interpreter to it. (I suggest this instead of using a Python repl because the way they have their Python REPLs set up adds a bunch of extra tools that need to be reconfigured; a bash repl keeps it simple).
Create a new bash repl.
Click on the three-dots menu.
Select "Show Hidden Files".
Open the file named replit.nix
Edit the file by adding a Python interpreter with pandas, as follows:
{ pkgs }: {
deps = [
pkgs.bashInteractive
(pkgs.python38.withPackages (p: [p.pandas]))
];
}
...changing that to taste (as long as they're getting software from a channel that has binaries for Python 3.9 or 3.10, for example, you can change python38 to python39 or python310).
Click the "run" button
In the new shell that opens, run python, and see that you can import pandas without trouble.
If, after you add a Python file to your repl, you can also change the .replit hidden file to make it run that file automatically on startup. Note that on NixOS, you should use #!/usr/bin/env python as your shebang, as PATH lookups are essential.

Blender opencv-python dllLoadError

I'm using Blender 2.78 (64bit) with Python 3.5.2 on Windows 7 (64bit). My situation is that I want to use opencv in combination with python in Blender. I went in serious trouble trying so and was working for days without any obvious success..
However from googling I found that there is a way to install pip as a module for blenders python and with pip I was able to install modules such as numpy oder scipy. This indeed also worked with opencv as it got successfully installed (including positive checks). It looked fine. But as I tried to import cv2 in a Console in Blender I got the error like the thread starter above:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.78\python\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I then tried to start blender python in an external shell and retried the import process resulting in the same error.
Next was retrying the complete procedure for my system python (same version 3.5.2) and everything worked perfectly.
From now on I was a bit confused as "pypi.python.org/pypi/opencv-python" towards opencv-python states that everything is linked statically and everything you have to do is what I have done. Looking in the FAQ the error is mentioned. You get the advise to check visual c++ redistributable and c runtime library. I did so, however, both is up to date and on system python opencv works perfectly that way.
Next try. As the system python works perfectly with opencv I removed blender python and pasted a copy of the system python instead. According to "blender.stackexchange.com/questions/5287/using-3rd-party-python-modules"
this is an alternative from using blenders own python.
Numpy, Scipy imports work perfectly. Importing cv2 leads to the same error as before.
If I now start the system-python copy that now is blenders python from a command shell cv2 can be imported.
Where is the difference here in the environment blender creates and the one from the shell??
I have installed a tool named listDlls to list all the dlls loaded by specific processes in order to compare blender-python and python. You can see some differences but I dont understand the matter of those except from the absence of the cv2 pyd in blenders python.
Any ideas?
First list is the python-process list, second the blender list:
https://ufile.io/uidy1
https://ufile.io/1eshi

How should I use cx_freeze with a Macports library?

I'm currently using the Python 3.4 Mac OS X build from Python.org. I'm using a Python module that depends on a library that I built in Macports. The script does not run out-of-the-box:
Traceback (most recent call last):
File "magnetx.py", line 6, in <module>
import yara
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/yara.so, 2): Library not loaded: /usr/local/lib/libyara.3.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/yara.so
Reason: image not found
I can fix this if I set an environment variable
export DYLD_FALLBACK_LIBRARY_PATH="/opt/local/lib:$DYLD_FALLBACK_LIBRARY_PATH"
Unfortunately, it does not satisfy cx_freeze. It keeps looking in /usr/local/lib, when it should be looking in /opt/local/lib.
copying
/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/yara.so
-> build/exe.macosx-10.6-intel-3.4/yara.so copying /usr/local/lib/libyara.3.dylib ->
build/exe.macosx-10.6-intel-3.4/libyara.3.dylib error: [Errno 2] No
such file or directory: '/usr/local/lib/libyara.3.dylib'
I could probably build Python in Macports, but that seems like it should be unnecessary. Any ideas on how to fix this?
On OS X, dependent libraries are referenced using absolute paths. The path that gets copied into your binary depends on the so-called "install name" of the library you link against at build time. In your case, the yara.so does not reference the library you would like it to load. Let's explore a couple of reasons why this could be the case, and a couple of ways to fix that:
I've verified that libyara.dylib as installed by MacPorts (on my system) has an install name of /opt/local/lib/libyara.0.dylib. Sometimes, build systems that don't use a cross-platform library build tool and don't expect the peculiarities of OS X mess this up (and use relative paths or /usr/local/lib). If this was the case, it would be a bug in the software's build system, which could be manually fixed using install_name_tool(1)'s -id flag (before linking against the library).
Your copy of yara.so may have been built against a different version of libyara.dylib that resides in /usr/local/lib. That would explain why your yara.so does not contain the correct absolute path to the MacPorts copy of libyara.dylib, but it would also prevent the error you're seeing from happening in the first place, unless you had a copy in /usr/local/lib at build time and deleted it later on. As you've already seen, you can instruct OS X' loader to also search different paths using the DYLD_* series of environment variables. My take on why this doesn't work for cx_freeze is that it doesn't pay attention to the DYLD_* series of variables.
If you are sure that the copy of libyara.dylib yara.so expects to find in /usr/local/lib is binary-compatible with the one in /opt/local/lib, you can manually modify the library load commands in yara.so to point to the latter path using install_name_tool(1)'s -change old new parameter, e.g. install_name_tool -change /usr/local/lib/libyara.3.dylib /opt/local/lib/libyara.0.dylib /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/yara.so. This is essentially modifying the binary with the change the loader did for you when you set DYLD_FALLBACK_LIBRARY_PATH. Since the library major version numbers seem to be different, this may not be a safe assumption.
If you don't know whether yara.so is compatible with MacPorts' build of libyara.0.dylib, you can and should recompile yara.so. If the re-compile went right, you should be able to check the library load commands using otool -L yara.so and see the paths beginning with /opt/local in there (provided that otool -D /opt/local/lib/libyara.0.dylib correctly points to itself).
Edit: I've just re-checked and noticed that my MacPorts build's library version number differs from the one your system expects. That sounds a lot like case number 2 to me.

Why doesn't import work for me? - Python

Whenever I try to import a file into python, it comes up with this error(or similar):
Traceback (most recent call last):
File "C:/Python33/My Files/username save.py", line 1, in <module>
import keyring.py
ImportError: No module named 'keyring'
I am trying to create a password storing program, and I was looking up for good ways to keep passwords secure, and someone said use import keyring, so I did, except, it never works. I must be doing something wrong, but whenever I look anything up for python, it never works out for me. It's almost as if loads have things have been changed over the years.
and idea's?
The keyring module is not part of the Python standard library. You need to install it first. Installation instructions are included.
Once installed, use import keyring, not import keyring.py; the latter means import the py module from the keyring package. Python imports should use just the name of the module, so not the filename with extension. Python can import code from more than just .py python files.
I was getting the same error "ModuleNotFoundError: No module named 'keyring'". And after installing this module pip install keyring, the same error occured with another module name. Then I came to the conclusion that it is the fact that the VSCode is not able to connect to my venv, even after setting the Python Itereptor. Press CTRL + SHIFT + P, and then type Python: Select Interceptor, and select your venv, if you want to set this.
To fix the issue, I had to force the VSCode to use the .venv I created, and luckily there is a dropdown to do that, on the top right corner as in the preceeding image. Click ont the Python version, and then you will be able to select your virtual environment.
Now it will take the modules from your virtual environment.

Categories