i am use microsoft azure (for students) ML servise. Then i work with notebook i can not import pytorch-lightning libary.
!pip install pytorch-lightning==0.9.0
import pytorch_lightning as pl
Here i have error:
ModuleNotFoundError Traceback (most recent call last)
Input In [1], in <module>
----> 2 import pytorch_lightning as pl
ModuleNotFoundError: No module named 'pytorch_lightning'
This is unbearably weird. someone faced such a problem?
This is rather strange but could be related to that your installation is in another location, so let's:
try where is PL installed with find -name "lightning"
also, check what is the loaded package locations python -c "import sys; print(sys.path)"
I guess that the problem will be in What's the difference between dist-packages and site-packages?
I resolved this problem by installing PyTorch-lightning in the kernel instead of the machine. It all boils down to installing with %conda magic instead of !conda magic (or same thing for %pip magic instead of !pip magic).
Related
I am running a Python package called pymatgen in Jupyter. Jupyter and pymatgen are installed in a conda environment. I have manually installed ruamel using conda's python3, but the same error occurs. The strange thing is that the same code (in this case just a library load statement) gives no errors when run with ipython. Both Jupyter and ipython are running from the miniconda installation (I check with the command which). I noticed some postings on the web stating that ruamel has problems with conda due to the remapping of a "." to an underscore character, but none of the proposed solutions helped the above problem. I also don't understand why ipython is fine and Jupyter fails. Any suggestions?
from pymatgen.core.structure import Structure, Lattice
from pymatgen.core.periodic_table import Element
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-753da7cc5963> in <module>
----> 1 from pymatgen.core.structure import Structure, Lattice
2 from pymatgen.core.periodic_table import Element
~/.local/lib/python3.7/site-packages/pymatgen/__init__.py in <module>
13 import os
14 import warnings
---> 15 import ruamel.yaml as yaml
16 from fnmatch import fnmatch
17
ModuleNotFoundError: No module named 'ruamel'
Use the below command to install it:
pip install ruamel.yaml
I have installed 'pandas_profiling' through conda install -c conda-forge pandas-profiling in the base environment. I could see through the conda list that pandas_profiling has been installed correctly (snapshot attached),
When I try to import pandas_profiling I receive ModuleNotFoundError
import pandas_profiling
Traceback (most recent call last):
File "<ipython-input-4-60d2bac64bfc>", line 1, in <module>
import pandas_profiling
ModuleNotFoundError: No module named 'pandas_profiling'
Update: output of import sys; print(sys.path); print(sys.prefix)
['/home/user1/miniconda3/lib/python38.zip', '/home/user1/miniconda3/lib/python3.8', '/home/user1/miniconda3/lib/python3.8/lib-dynload', '', '/home/user1/miniconda3/lib/python3.8/site-packages', '/home/user1/miniconda3/lib/python3.8/site-packages/IPython/extensions', '/home/user1/.ipython']
/home/user1/miniconda3
This is a frequent issue, check out this entry in the FAQ.
Occasionally you will encounter this error if you import a package from the current notebook. It is important to ensure that the pip version is associated with the current Python kernel. That way, the installed packages can be used in the current notebook.
As detailed here, the shell environment and the Python executable are disconnected.
This should work for you
import sys
!{sys.executable} -m pip install pandas-profiling
In the past I have installed the pymeep package in Google Colab with the following cell:
!wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!bash ./Miniconda3-latest-Linux-x86_64.sh -b -p ./anaconda
import os
os.environ['PATH'] += ":/content/anaconda/bin"
!conda create -n mp -c conda-forge pymeep
import sys
sys.path.append('/content/anaconda/envs/mp/lib/python3.7/site-packages/')
Which is an exact copy from this website: https://rf5.github.io/2019/12/22/meep-intro.html
Sometimes the code I wrote doesn't work. It executes without errors, but when I try to execute import meep as mp. I get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-f30f3b609667> in <module>()
----> 1 import meep
ModuleNotFoundError: No module named 'meep'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Is there a better way of installing meep or rather pymeep in Google Colab?
Replace 3.7 with 3.8 as the latest python version installed using conda is 3.8
sys.path.append('/content/anaconda/envs/mp/lib/python3.8/site-packages/')
Example
I am trying to import the GeoPandas module (which I had recently installed on my laptop) in a Jupyter notebook but it returning this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-a62d01c1d62e> in <module>
----> 1 import geopandas as gpd
ModuleNotFoundError: No module named 'geopandas'
I am certain that geopandas installed correctly. Can someone please suggest a fix?
It may not be installed in the right kernel for your jupyter notebook. One way to fix this is to run %pip install geopandas in a cell in your notebook. Then you can restart the kernel and you should be able to import it.
edit
just tried this out again and I had to add a --user to the magic command. The final command should look like %pip install geopandas --user
For me, I had to manually install the libraries as i could not import them although they were present in pip list of installed packages.
I went to https://www.lfd.uci.edu/~gohlke/pythonlibs/, where I downloaded the compatible version for GDAL, Pyproj, Fiona, Shapely and Geopandas.
Then I manually installed them using:
pip install the file path
Good evening,
I am trying to import datascience module at my Jupyter notebook, but the notebook keeps showing error called
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-10-6f3a305c96af> in <module>()
----> 1 from datascience import *
ModuleNotFoundError: No module named 'datascience'
although I have done
pip install --user datascience
Could anyone solve this problem for me?
Thank you in advance
first, check whether you have installed datascience package in to the same environment.
use pip freeze to list installed packages.
if it's installed correctly, then try this.
import datascience as dt
then you can access ant function in datascience package.
`dt.function()`
Perhaps these links can help you :
link, link 2 and link 3
First, activate your environment if you have it.
Second, check your project path.
Third, try to install your package one more time.
Fourth, use freezing to check if a module is installed.
Five, check if the import is well done.