I need to write a code using jupyter notebook but need imagej packages.
I installed pyimagej using several commands
conda install -c conda-forge pyimagej
conda install -c conda-forge/label/cf201901 pyimagej
conda install -c conda-forge/label/cf202003 pyimagej
But I always get this error: ModuleNotFoundError: No module named 'ij'
when I try
from ij import IJ
I know that I can use imagej editor but I need to use jupyter notebook. Could someone help?
I tried this and it worked
conda create -n imagej pyimagej
We have recently improved our documentation on how to use PyImageJ. It looks like you were successful in installing the software, but you did not yet initialize PyImageJ. Checkout the How to initialize PyImageJ. If you have trouble initializing PyImageJ, you might need to view the installation documentation.
But assuming you have installed PyImageJ and activated your environment, a typical script looks something like this:
import imagej
# initialize PyImageJ
ij = imagej.init('sc.fiji:fiji', mode='interactive')
print(f"ImageJ Version: {ij.getVersion()}")
# The original ImageJ "IJ" is a property of the initialized "ij" object.
print(dir(ij.IJ))
Hope that helps!
Related
I want to import MeCab and use it, but that error comes out repeatedly.
MeCab-python is well installed.
I've tried Brew install and so on, and it's still the same.
I'd appreciate it if you could help me if you knew the solution.
Hmm. On a fresh macOS 13.1 Ventura, I just did this:
Installed miniconda https://docs.conda.io/en/latest/miniconda.html#latest-miniconda-installer-links
conda create -n mecab-tutorial and answering questions
conda activate mecab-tutorial
conda install python ipython and saying 'yes'
python -m pip install mecab-python3 unidic-lite
Then I was able to run this script:
import MeCab
wakati = MeCab.Tagger("-Owakati")
wakati.parse("pythonが大好きです").split()
# ['python', 'が', '大好き', 'です']
Looking at the path in the error in the screenshot, it looks like you installed a global Python in /Library which I don't want to try because I very much prefer to keep my Python environments local, hence using Conda above to create a custom environment to install MeCab packages in to ensure no cross-contamination later.
There's no guarantee that this will work if you try it since the error you're seeing seems to be a compiler issue (Python is finding MeCab, just having trouble calling a C++ function inside the binary), but if possible, can you try the Conda approach above?
I need to use the sksparse.chomod package however my pycharm does not let me install it as it can't seem to find it.
I found the sksparse package on github and downloaded it but I do not know how to add a package downloaded from the internet into a conda environment. So, my first question would be can you download a package from github and add it to your conda environment, and how do you do this?
As I did not know how to do the above I instead saved the package within my project and thought I could simply import sksparse.cholmod. However, the line in my code that says import sksparse.cholmod as sks has no errors with it, so I assumed that meant this was ok, but when I try to run my file I get this error:
import sksparse.cholmod as sks
ModuleNotFoundError: No module named 'sksparse.cholmod'
If I have downloaded the package into my project why can't it be found, yet there are no errors when importing?
The cholmod file is a pyx file which I've been told should not be a problem.
Please could anyone help, I am reasonably new to python and I am looking for a straight forward solution that won't be time consuming.
It was an issue with windows, I was able to fix this using the instructions on this link
https://github.com/EmJay276/scikit-sparse
We must follow these steps precisely:
(This was tested with a Anaconda 3 installation and Python 3.7)
Install these requirements in order:
'''
conda install -c conda-forge numpy - tested with v1.19.1
conda install -c anaconda scipy - tested with v1.5.0
conda install -c conda-forge cython - tested with v0.29.21
conda install -c conda-forge suitesparse - tested with v5.4.0
'''
Download Microsoft Build Tools for C++ from https://visualstudio.microsoft.com/de/visual-cpp-build-tools/ (tested with 2019, should work with 2015 or newer)
Install Visual Studio Build Tools
Choose Workloads
Check "C++ Buildtools"
Keep standard settings
Run ''' pip install git+https://github.com/EmJay276/scikit-sparse '''
Test ''' from sksparse.cholmod import cholesky '''
Use all the versions stated for numpy etc, however with scipy I installed the latest version and it worked fine.
I'm looking for a way to get a list of all installed/importable python modules from a within a Jupyterlab notebook.
From the command line, I can get the list by running
py -3 -m pip freeze
(or)
pip freeze
In the Jupyterlab console, running pip freeze returns
The following command must be run outside of the IPython shell:
$ pip freeze
The Python package manager (pip) can only be used from outside of IPython.
Please reissue the `pip` command in a separate terminal or command prompt.
See the Python documentation for more information on how to install packages:
https://docs.python.org/3/installing/
For older versions of pip, it was possible to import pip and get a list from within a notebook.
The command was
help('modules')
This now gives a warning and returns nothing.
c:\python37\lib\site-packages\IPython\kernel\__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated since IPython 4.0.You should import from ipykernel or jupyter_client instead.
"You should import from ipykernel or jupyter_client instead.", ShimWarning)
10 year old stackoverflow solutions like How can I get a list of locally installed Python modules? also no longer work.
Is there a proper way of doing this (without using a subprocess hack or running pip as an external program like "!pip")
You may run following snippet to the result.
!pip list
you can also try
!pip freeze
in your jupyter notebook. Hope it helps you.
import pip._internal.operations.freeze
_ = pip._internal.operations.freeze.get_installed_distributions()
print(sorted(["%s==%s" % (i.key, i.version) for i in _])[:10])
['absl-py==0.7.1',
'aiml==0.9.2',
'aio-utils==0.0.1',
'aiocache==0.10.1',
'aiocontextvars==0.2.2',
'aiocqhttp==0.6.7',
'aiodns==2.0.0',
'aiofiles==0.4.0',
'aiohttp-proxy==0.1.1',
'aiohttp==3.6.2']
This works in Win10 with Python 3.6 & 3.7 (ipython, pip.version: '20.0.1') at least. I took a look at the source code in Lib\site-packages\pip.
Try this :
help("modules")
....
%pip list
instead of
!pip list
Using the macOS terminal, I'm trying to run ./autoner_train.sh by following this guide on GitHub.
I have activated my Conda environment and check my PyTorch version
(pytorch_env) myname (master) AutoNER $ python -c "import torch; print(torch.__version__)"
1.3.1
After that, when running, I get the following error
ModuleNotFoundError: No module named 'torch_scope'
I don't know where's the problem. I have installed everything and I tried googling the problem, all I found is that I need PyTorch installed, which I already have.
I the documentation at the Dependencies section you can read:
Dependencies
This project is based on python>=3.6. The dependent package for this
project is listed as below:
numpy==1.13.1
tqdm
torch-scope>=0.5.0
pytorch==0.4.1
So you need to install torch-scope>=0.5.0 too:
pip install torch-scope
I have been trying to get the gdal library work using Python 2.7 and Anaconda in Windows 8 environment.
Besides gdal, I have also installed libgdal (frankly, I don't really understand the difference between the two). I now seem to have gdal 2.1.0 and 2.0.2 as well as libgdal 2.1.0.
However, when I run my Py code, there is a gdal error:
'gdalwarp' is not recognized as an internal or external command,
operable program or batch file.
I have already set the GDAL_DATA environmental variable to point to
C:\Anaconda\pkgs\libgdal-2.1.0-vc9_0\Library\share\gdal
I have also added a path, although I am not entirely sure where this should point to:
C:\Anaconda\pkgs\libgdal-2.1.0-vc9_0\Library\bin
I have tried the same with gdal 2.0.2 without success. gdalwarp.exe does seem to exist under libgdal 2.1.0 and gdal 2.0.2.
Any ideas? Is there an issue with the installation or have I not set the environmental variables correctly?
FYI, I have tried various installation commands, notably:
conda install gdal
conda install -c conda-forge gdal
conda install -c anaconda gdal
Addendum: I have found a manual solution: I set the GDAL_DATA and PATH variables in the terminal (pointing to libgdal 2.1.0) before running the code...
However, there is still an issue when I run my Py code: it is supposed to convert a tiff file to shp with gdal_polygonize:
cmd = 'gdal_polygonize.py %s -f "ESRI Shapefile" %s'%(dst_tif, dst_shp)
There is no error but the shapefile is not created (which leads to an error later on in the code). Any ideas as to why gdal is still not working correctly?
I have tried pointing the env variables to osgeo:
set PATH=%PATH%;C:\Anaconda2\Lib\site-packages\osgeo\scripts
set GDAL_DATA=C:\Anaconda2\Lib\site-packages\osgeo\data\gdal
Gdalinfo works but the gdal_polygonize used in my Py code does not appear to work.
The key is the activation script which is (potentially) executed when activating the environment. Not every GDAL build for Conda contains this. In my experience recent Conda-Forge builds are really good.
With your requirements of py27 and GDAL 2.1 i can get it working by following these steps:
1) Create a new environment: conda create -n gdaltest python=2.7
2) Activate: activate gdaltest
3) Install GDAL: conda install gdal=2.1 -c conda-forge
4) Reactivate environment: deactivate + activate gdaltest
This forces the just installed activation script to be executed, this sets the environment variables.
If i start python and run os.system("gdalinfo"), i can see its picked up correctly. And running os.environ['GDAL_DATA'] confirms the path is set correctly.
You can view the (de)activation script yourself at:
C:\Miniconda3\envs\<env name>\etc\conda\activate.d\gdal-activate.bat
A few years ago this didn't work as well as it does today, so make sure you have a recent Conda version (4.3.x) etc.
The benefit of this method is, that when switching environments, your paths are also changed accordingly. A "hard coded" GDAL_DATA path could potentially cause some compatibility issues if you mix and match different GDAL versions (although normally is should work OK).