No module named pandas in conda command prompt - python

I'm trying to run a script made on spyder that runs with no problem.
But when I try to run the same script it says Pandas is not installed.
But I checked on my conda env e seems to be already installed.
Why this happens?

Problem
You are using pip python's default package manager to install a package in python's default location.
But using Anaconda's virtual environment to run python script which requires packages to be installed in it's own directory via conda package maanger.
Solution
Run this command in Conda command pompt:
conda install -c conda-forge pandas

Related

With Mamba, pypy cannot find modules installed using pip?

I'm testing using pypy for speeding up the execution time of a Python script I wrote. To install the dependencies of the script, I used both pip (some modules I need are not available via anaconda) and Mamba.
When I run the script using pypy script.py, I get an error message saying that the modules I installed using pip are not found (example: ImportError: No module named presidio_analyzer). Why does this happen? And do you have suggestions on how to fix this?
I'm running the tests on OSX. I installed Mamba using micromamba.
To make this work you should:
Create a conda environment that contains python and pip.
Activate the conda environment
Run pip install ...
Run pypy script.py
When you run pip install ... using an instance of pip that is part of your conda environment, then the python packages also get installed into the conda environment.
Your conda environment should also be activated when you run pypy script.py so that the python binary within the conda environment is utilized along with the packages you pip installed.

Installed a package on command line and can import it via command line. Receive ModuleNotFoundError when importing in jupyter notebook

I installed the python package lifelines on my terminal. The windows terminal is my terminal of choice, with a powershell and anaconda terminal that I often used.
I tried installing the package using the provided commands in the documentation:
pip install lifelines
and
conda install -c conda-forge lifelines
Both times the installation is marked as successfull. When I run Python within the terminal I can import the lifelines package without problem. However whem I import it on a jupyter notebook it yields a ModuleNotFoundError.
The base environment I use does not contain the lifelines package when I verify its contents using the Anaconda Navigator.
The jupyter notebooks are run on Anaconda Powershell, and so are the environments and packages.
Installing on the Windows Powershell will never work. Running the conda install -c conda-forge lifelines in the Anaconda shell solved the issue.
So silly, yet so time consuming it is worth sharing.
I had a issue like this, python3 -m pip install <package_name> solved it for me. Use python -m pip install <package_name> for Python2.

Installing python packages on anaconda on macos

This may be a silly simple question, but I couldn't find an answer in the documentation of Anaconda or elsewhere. I am a bit of a noob when it comes to Python and I am trying to install a package. The problem is generalizable to other packages.
specs
I am working on a macOS Catalina (10.15.5) and using Anaconda as my python environment (python2.7).
problem
I am attempting to install the package pyLDAvis in my python environment, but the package isn't available on Anaconda's environment manager, and pip or conda install isn't working on the Spyder shell. Do pip and conda installs only work on the Anaconda Prompt? The problem is that I have read that the Anaconda Prompt only exists on Windows, and I am on mac. How could I install packages (pip, conda, or else) on Anaconda?
Am I missing something?
Any help or pointers to documentation would be great! Thanks
Assuming you have conda already installed and your shell is properly configured, you can activate the base environment via
conda activate
You can also create a new environment, see manage-environments docs.
For more information than given below, see manage-pkgs docs.
In case of conda, after your environment is activated, you can then install a package via conda install <package name>, e.g. the package numpy
conda install numpy
In case of pip, after your environment is activated, you can then install a package via pip install <package name>, e.g. the package numpy
pip install numpy
I only do this if the package is not available via a conda channel.
If the package is also not available via pip, you can download the source and set the package up your self. Usually the package author describes how to set up his/her package.
Thanks Stefan for the suggestion! I struggled a bit because although conda was "already installed", my shell was indeed not "properly configured." I am writing here my solution because it may be a recurring theme for macOS users and had an easy fix.
Starting with macOS Catalina, macOS uses zsh and not bash as the default shell, and so calling conda on zsh had no effect. The error message was: -zsh: conda: command not found. I solved this by changing the default shell to bash by running the following command: chsh -s /bin/bash.
Now that the shell and conda are properly configured, I managed to use conda activate as you suggested Stefan.
Finally, the package pyLDAvis could not be installed by conda install pyldavis but was installed with pip install pyldavis.
Solved!

Trying to install a pip package in Anaconda

I'm trying to follow this tutorial:
https://learn.microsoft.com/en-us/azure/machine-learning/service/tutorial-data-prep
As part of this I'm trying to do a pip install of azureml as it's not available on conda. However doing a pip install will by default install it to my default python install, and not my conda install.
So I tried following the steps here:
https://conda.io/docs/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
However after following these steps I then launch Jupyter notebook after activating myenv, navigate to the notebook, and try and run:
import azureml.dataprep as dprep
But get the error: ModuleNotFoundError: No module named 'azureml'
Also - I cannot tell if myenv is active in the notebook. The kernel simply says python3.
Be careful, when using pip in anaconda, it is possible that you are mixing pip and pip3.
Run which pip3 to be sure you are using the version that correspond to the virtual environment.
If you are using python3 in the environment, then pip will typically be the correct version to use. Do not use pip3 in that case.
This problem has been documented elsewhere on the web. The problem is that Jupyter notebooks itself only launches in the root environment by default. The simplest solution to getting it to launch for your env (e.g. myenv) is to install Jupyter within your env first. So from the Anaconda command prompt:
activate myenv
pip install jupyter
jupyter
Ps. Use source activate myenv for non-windows machines

How do I automatically run on an environment with Spyder?

Sorry if I am unclear/this is a lame question, still very new to setting up my computer.
So I installed Python using Anaconda for work, and at work there are specific packages that are used internally. I used Anaconda Prompt to install these packages by creating an environment and installing internally used packages. I then check to see if the package is there.
In the Anaconda Prompt...
conda create --name environment_name python = 3.4
activate environment_name
pip install <internal package> --upgrade
pip list
However, when I try to import a package on Spyder, it does not recognize the package. Is there a way for Spyder to run code on an environment that I specify? I would like the environment to run automatically on any file that I run using Spyder, being able to pull the packages that I installed on Anaconda Prompt

Categories

Resources