Getting Import error after installing packages through conda
You won't be able to import those packages from native installed python/python3 environments (unless you've installed them using pip
/pip3
). Anaconda uses virtual environments (the default one is called base).
You have to activate base virtual environment and use its python in order to install additional packages using pip
/pip3
or import Anaconda's preinstalled packages :
conda activate base
python
>>> import pandas
>>> exit()
conda deactivate
OR
conda activate base
python3
>>> import pandas
>>> exit()
conda deactivate
You can check installed packages inside base virtual environment using :
conda activate base
pip list
pip3 list
conda deactivate
If u have several conda environment (other than base), you can list them using :
conda env list
Finally, you can run your scripts using :
conda activate env_name # env_name is probably base in your case
python script.py
conda deactivate
OR
conda activate env_name
python3 script.py
conda deactivate
Related videos on Youtube
mystical_starseed
Updated on September 18, 2022Comments
-
mystical_starseed over 1 year
I just installed
pandas
,BeautifulSoup4
,Jinja2
alongsideconda
distribution, but I'm not able to import any of the packages exceptnumpy
and others which come pre-installed withconda
.Where am I doing this wrong?
Here is a screenshot of my terminal window, where you can see the
ImportError and ModuleNotFoundError
in Python 2 and 3 respectively. I didn't trypip
because I thought it might make things worse by breaking something.-
Melebius over 4 yearsPlease do not post screenshots of the terminal. Paste the text directly to your question and apply code formatting.
-
crissal over 4 yearsIf you need global-level packages, just use
python(3) -m pip install <packages>
-
-
mystical_starseed over 4 yearsthanks for the response, but I'm not able to
import pandas
in(base) env
in python3, I just checked, it's working when using python -
pymym213 over 4 yearsyou've created a python2 conda environment (done by default), if you want to create a python3 env, run
conda create -n mypython3env python=3
-
mystical_starseed over 4 yearsNow, I get it. Thanks
-
pymym213 over 4 yearsmore details here : salishsea-meopar-docs.readthedocs.io/en/latest/work_env/…