Unable to import a package that seems to have been installed - python

I am trying to work with the TimeSynth Python package in my Conda environment. It is not available on the pkgs list or conda-forge list of Conda-supported packages, so I found this post that seems to get around the issue by installing the package in the Conda environment using pip.
I followed the instructions in the accepted answer, however when I do the last step:
.conda/envs/tcl/bin/pip install timesynth
(tcl is the name of my environment)
It says the requirement is already satisfied:
Requirement already satisfied: timesynth in
./.conda/envs/tcl/lib/python3.6/site-packages (0.2.4)
Requirement already satisfied: scipy in
./.conda/envs/tcl/lib/python3.6/site-packages (from timesynth) (1.4.1)
Requirement already satisfied: jitcxde-common==1.4.1 in
./.conda/envs/tcl/lib/python3.6/site-packages (from timesynth) (1.4.1)
Requirement already satisfied: numpy in
./.conda/envs/tcl/lib/python3.6/site-packages (from timesynth)
(1.18.1)
Requirement already satisfied: sympy in
./.conda/envs/tcl/lib/python3.6/site-packages (from timesynth) (1.8)
Requirement already satisfied: symengine==0.4 in
./.conda/envs/tcl/lib/python3.6/site-packages (from timesynth) (0.4.0)
Requirement already satisfied: jitcdde==1.4 in
./.conda/envs/tcl/lib/python3.6/site-packages (from timesynth) (1.4.0)
Requirement already satisfied: jinja2 in
./.conda/envs/tcl/lib/python3.6/site-packages (from
jitcxde-common==1.4.1->timesynth) (3.0.0a1)
Requirement already satisfied: setuptools in
./.local/lib/python3.6/site-packages (from
jitcxde-common==1.4.1->timesynth) (56.2.0)
Requirement already satisfied: MarkupSafe>=1.1 in
./.conda/envs/tcl/lib/python3.6/site-packages (from
jinja2->jitcxde-common==1.4.1->timesynth) (2.0.0)
Requirement already satisfied: mpmath>=0.19 in
./.conda/envs/tcl/lib/python3.6/site-packages (from sympy->timesynth)
(1.2.1)
However when I run a Python script that imports timesynth, it doesn't recognize the module. Any advice?
EDIT:
Per request, here is the start of the file I'm trying to use timesynth in:
import numpy as np
import TimeSynth.timesynth as ts
import matplotlib.pyplot as plt
import seaborn as sns; sns.set()
And the error cites line 2 and states:
ModuleNotFoundError: No module named 'TimeSynth'

Following the TimeSynth library's example, the import statement of OP
import TimeSynth.timesynth as ts
should instead be
import timesynth as ts

Related

No module named seaborn even if I installed it

I got a problem with seaborn. When I run poetry, the shell said that No module named 'seaborn' even I install it by pip install seaborn:
$ pip install seaborn
Requirement already satisfied: seaborn in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (0.10.0)
Requirement already satisfied: scipy>=1.0.1 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from seaborn) (1.4.1)
Requirement already satisfied: matplotlib>=2.1.2 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from seaborn) (3.2.0)
Requirement already satisfied: pandas>=0.22.0 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from seaborn) (1.0.1)
Requirement already satisfied: numpy>=1.13.3 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from seaborn) (1.18.1)
Requirement already satisfied: cycler>=0.10 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib>=2.1.2->seaborn) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib>=2.1.2->seaborn) (2.4.6)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib>=2.1.2->seaborn) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib>=2.1.2->seaborn) (1.1.0)
Requirement already satisfied: pytz>=2017.2 in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from pandas>=0.22.0->seaborn) (2019.3)
Requirement already satisfied: six in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from cycler>=0.10->matplotlib>=2.1.2->seaborn) (1.14.0)
Requirement already satisfied: setuptools in c:\users\administrator\appdata\local\programs\python\python38-32\lib\site-packages (from kiwisolver>=1.0.1->matplotlib>=2.1.2->seaborn) (41.2.0)
When I check the import as this question: How to import seaborn in Python? (by python -c "import seaborn"), the shell run in about 8 - 10 seconds but nothing appear next.
What is the problem? What should I do to fix it error? Do I install seaborn properly? I'm using Windows, git bash as shell and Python 3.8.2.
If you are using poetry as a dependency manager, you need to install the dependency for the poetry virtual environment.
Just add a line in the pyproject.toml file under the:
[tool.poetry.dependencies]
seaborn = "^0.9.0"
And then run the command poetry install. The next time you run your project, it will have seaborn installed in the environment the project is running.

No module named 'gensim' but already installed it

i'm having this error problem, i have ran this script in jupyter notebook in base (root) environment, the log said that gensim library has been installed and i have run the command !pip install gensim before i import it, but it still can not be imported, and the error said ModuleNotFoundError: No module named 'gensim'
!pip install gensim
import gensim
from gensim.models import KeyedVectors
model = KeyedVectors.load('model_fasttext2.vec')
model.vector_size
------------------------------------------------------------------------
Requirement already satisfied: gensim in c:\users\ip-03\anaconda3\lib\site-packages (3.8.1)
Requirement already satisfied: scipy>=0.18.1 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.4.1)
Requirement already satisfied: six>=1.5.0 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.14.0)
Requirement already satisfied: smart-open>=1.8.1 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.9.0)
Requirement already satisfied: numpy>=1.11.3 in c:\users\ip-03\anaconda3\lib\site-packages (from gensim) (1.18.1)
Requirement already satisfied: boto>=2.32 in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (2.49.0)
Requirement already satisfied: boto3 in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (1.12.3)
Requirement already satisfied: bz2file in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (0.98)
Requirement already satisfied: requests in c:\users\ip-03\anaconda3\lib\site-packages (from smart-open>=1.8.1->gensim) (2.22.0)
Requirement already satisfied: s3transfer<0.4.0,>=0.3.0 in c:\users\ip-03\anaconda3\lib\site-packages (from boto3->smart-open>=1.8.1->gensim) (0.3.3)
Requirement already satisfied: botocore<1.16.0,>=1.15.3 in c:\users\ip-03\anaconda3\lib\site-packages (from boto3->smart-open>=1.8.1->gensim) (1.15.3)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in c:\users\ip-03\anaconda3\lib\site-packages (from boto3->smart-open>=1.8.1->gensim) (0.9.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (2019.11.28)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in c:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (3.0.4)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (1.25.8)
Requirement already satisfied: idna<2.9,>=2.5 in c:\users\ip-03\anaconda3\lib\site-packages (from requests->smart-open>=1.8.1->gensim) (2.8)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\users\ip-03\anaconda3\lib\site-packages (from botocore<1.16.0,>=1.15.3->boto3->smart-open>=1.8.1->gensim) (2.8.1)
Requirement already satisfied: docutils<0.16,>=0.10 in c:\users\ip-03\anaconda3\lib\site-packages (from botocore<1.16.0,>=1.15.3->boto3->smart-open>=1.8.1->gensim) (0.15.2)
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-10-ee4a48d372cd> in <module>
1 get_ipython().system('pip install gensim')
----> 2 import gensim
3 from gensim.models import KeyedVectors
4 model = KeyedVectors.load('model_fasttext2.vec')
5 model.vector_size
ModuleNotFoundError: No module named 'gensim'
Is there anyone who can help this problem? i will really appreciate your help, it will help my thesis work, thank you for your attention
It may be that your jupyter lab maybe running the base kernel and not the kernel of the virtual environment.
Check by doing the following:
import sys
sys.executable
into my notebook and got the result
'/anaconda3/bin/python'
If you get the above instead of the below then that means you're using the wrong kernel.
'/anaconda3/envs/myenv/bin/python'
You can solve it by creating a new iPython kernel for your new environment. Read more here.
conda install -n myenv ipython
conda activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
```Then, to run Jupyter Lab in the new environment:

ModuleNotFoundError: No module named 'matplotlib' even when matplotlib is installed

I can't seem to import matplotlib.
import matplotlib
ModuleNotFoundError: No module named 'matplotlib'
Trying conda list matplotlib give the following output:
# Name Version Build Channel
matplotlib 3.1.1 py37_1 conda-forge
matplotlib-base 3.1.1 py37h2852a4a_1 conda-forge
I tried to install it using pip: pip install matplotlib. It resulted in:
Requirement already satisfied: matplotlib in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (3.1.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from matplotlib) (1.1.0)
Requirement already satisfied: numpy>=1.11 in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from matplotlib) (1.16.5)
Requirement already satisfied: python-dateutil>=2.1 in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from matplotlib) (2.8.0)
Requirement already satisfied: cycler>=0.10 in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from matplotlib) (2.4.2)
Requirement already satisfied: setuptools in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from kiwisolver>=1.0.1->matplotlib) (41.4.0)
Requirement already satisfied: six>=1.5 in c:\programdata\anaconda3\envs\tf-gpu\lib\site-packages (from python-dateutil>=2.1->matplotlib) (1.12.0)
What should I do?
Edit: I later found that i could import it in my base env. But still can't do it in tf-gpu env

ImportError: No module named flask_toastr

I want to use Toastr, for showing non-blocking notifications in my Flask app. I already installed the package with pip :
sudo pip install Flask-Toastr
Here is the output of the installation
Requirement already satisfied: Flask-Toastr in
/Users/****/.local/lib/python3.7/site-packages (0.5.2)
Requirement already satisfied: Flask in
/Users/****/anaconda3/lib/python3.7/site-packages (from Flask-Toastr)
(1.1.1)
Requirement already satisfied: Jinja2 in
/Users/****/anaconda3/lib/python3.7/site-packages (from Flask-Toastr)
(2.10.1)
Requirement already satisfied: click>=5.1 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Flask->Flask-Toastr) (7.0)
Requirement already satisfied: Werkzeug>=0.15 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Flask->Flask-Toastr) (0.15.4)
Requirement already satisfied: itsdangerous>=0.24 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Flask->Flask-Toastr) (1.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in
/Users/****/anaconda3/lib/python3.7/site-packages (from
Jinja2->Flask-Toastr) (1.1.1)
Here is theimport statement:
from flask_toastr import Toastr
But when I run my script I have this ImportError. How can I fix this? Thank you
Without seeing your import statement I suspect you have used a '-' instead of an underscore in the import statement:
Try this:
from flask_toastr import Toastr

Installing Matplotlib with PIP

When I try to run my python script I get the following error
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
SO I tried to install Matplotlib using
"pip install matplotlib"
Then I get the error
Requirement already satisfied: matplotlib in
c:\users\harla\anaconda2\lib\site-packages
Requirement already satisfied: numpy>=1.7.1 in
c:\users\harla\anaconda2\lib\site-packages (from matplotlib)
Requirement already satisfied: six>=1.10 in
c:\users\harla\anaconda2\lib\site-packages (from matplotlib)
Requirement already satisfied: python-dateutil in
c:\users\harla\anaconda2\lib\site-packages (from matplotlib)
Requirement already satisfied: functools32 in
c:\users\harla\anaconda2\lib\site-packages (from matplotlib)
Requirement already satisfied: pytz in c:\users\harla\anaconda2\lib\site-
packages (from matplotlib)
Requirement already satisfied: cycler>=0.10 in
c:\users\harla\anaconda2\lib\site-packages (from matplotlib)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in
c:\users\harla\anaconda2\lib\site-packages (from matplotlib)
I know I have installed anaconda. I don't want to use Anaconda for this. How do I install the library matplotlib ?
I solved it by removing the environment variable to C:\Users\harla\Anaconda2\Scripts_flag
Not sure if there is a better solution.

Categories

Resources