Conda install pandas выдает ошибку

I am using anaconda for this. I have downloaded pandas using both:

pip install pandas

and

conda install pandas

They successfully install, and doing the installation again shows that they are already installed. However, when writing this line alone

import pandas as pd

I get this error message:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-7dd3504c366f> in <module>
----> 1 import pandas as pd

ModuleNotFoundError: No module named 'pandas'

I have no idea what to do.

Helder's user avatar

Helder

4701 gold badge4 silver badges14 bronze badges

asked Mar 30, 2020 at 0:11

Joseph Chyzowzki's user avatar

2

Have you enabled the conda environment where pandas was installed? For example, if you created the env using conda env create -n myenv, then running the following before installing the package should help:

conda activate myenv

Where is pandas installed? If using linux you could try to run

locate "pandas/__init__.py"

to find where you have some copy of pandas.

answered Mar 31, 2020 at 12:10

Helder's user avatar

HelderHelder

4701 gold badge4 silver badges14 bronze badges

You don’t necesarilly need an environment for this.
The real deal with this problem is to know what pip or conda you are actually using and then on which python will the stuff be installed.

You can open python and:

import sys
sys.path

Like this you can know where your python is. Go to that folder and you’ll also find a pip.

Then you have two options:

1) Set this path on your environments variables => you won’t ever have the problem unless you try to do another python installation (then yes, use conda environment )

2) In you command prompt your/pip/path/pip install pandas

answered Mar 31, 2020 at 12:22

Ivan's user avatar

IvanIvan

1,3262 gold badges13 silver badges30 bronze badges

2

The error “ModuleNotFoundError: No module named pandas» is a common error experienced by data scientists when developing in Python. The error is likely an environment issue whereby the pandas package has not been installed correctly on your machine, thankfully there are a few simple steps to go through to troubleshoot the problem and find a solution.

Your error, whether in a Jupyter Notebook or in the terminal, probably looks like one of the following:

No module named 'pandas'
ModuleNotFoundError: No module named 'pandas'

In order to find the root cause of the problem we will go through the following potential fixes:

  1. Upgrade pip version
  2. Upgrade or install pandas package
  3. Check if you are activating the environment before running
  4. Create a fresh environment
  5. Upgrade or install Jupyer Notebook package

Are you installing packages using Conda or Pip package manager?

It is common for developers to use either Pip or Conda for their Python package management. It’s important to know what you are using before we continue with the fix.

If you have not explicitly installed and activated Conda, then you are almost definitely going to be using Pip. One sanity check is to run conda info in your terminal, which if it returns anything likely means you are using Conda.

Upgrade or install pip for Python

First things first, let’s check to see if we have the up to date version of pip installed. We can do this by running:

pip install --upgrade pip

Upgrade or install pandas package via Conda or Pip

The most common reason for this error is that the pandas package is not installed in your environment or an outdated version is installed. So let’s update the package or install it if it’s missing.

For Conda:

# To install in the root environment 
conda install -c anaconda pandas 

# To install in a specific environment 
conda install -n MY_ENV pandas

For Pip:‌

# To install in the root environment
python3 -m pip install -U pandas

# To install in a specific environment
source MY_ENV/bin/activate
python3 -m pip install -U pandas

Activate Conda or venv Python environment

It is highly recommended that you use isolated environments when developing in Python. Because of this, one common mistake developers make is that they don’t activate the correct environment before they run the Python script or Jupyter Notebook. So, let’s make sure you have your correct environment running.

For Conda:

conda activate MY_ENV

For virtual environments:

source MY_ENV/bin/activate

Create a new Conda or venv Python environment with pandas installed

During the development process, a developer will likely install and update many different packages in their Python environment, which can over time cause conflicts and errors.

Therefore, one way to solve the module error for pandas is to simply create a new environment with only the packages that you require, removing all of the bloatware that has built up over time. This will provide you with a fresh start and should get rid of problems that installing other packages may have caused.

For Conda:

# Create the new environment with the desired packages
conda create -n MY_ENV python=3.9 pandas 

# Activate the new environment 
conda activate MY_ENV 

# Check to see if the packages you require are installed 
conda list

For virtual environments:

# Navigate to your project directory 
cd MY_PROJECT 

# Create the new environment in this directory 
python3 -m venv MY_ENV 

# Activate the environment 
source MY_ENV/bin/activate 

# Install pandas 
python3 -m pip install pandas

Upgrade Jupyter Notebook package in Conda or Pip

If you are working within a Jupyter Notebook and none of the above has worked for you, then it could be that your installation of Jupyter Notebooks is faulty in some way, so a reinstallation may be in order.

For Conda:

conda update jupyter

For Pip:

pip install -U jupyter

Best practices for managing Python packages and environments

Managing packages and environments in Python is notoriously problematic, but there are some best practices which should help you to avoid package the majority of problems in the future:

  1. Always use separate environments for your projects and avoid installing packages to your root environment
  2. Only install the packages you need for your project
  3. Pin your package versions in your project’s requirements file
  4. Make sure your package manager is kept up to date

References

Conda managing environments documentation
Python venv documentation

I am also facing same error.please suggest steps if your problem is resolved:

(dlnd) C:UsersDipan AryaDesktopudadlnd-your-first-networkDLND-your-first-n
etwork>conda install pandas
Fetching package metadata ………..
Solving package specifications: .

Package plan for installation in environment C:ProgramDataAnaconda3envsdlnd:

The following NEW packages will be INSTALLED:

mkl:             2017.0.1-0
numpy:           1.11.3-py36_0
pandas:          0.19.2-np111py36_1
python-dateutil: 2.6.0-py36_0
pytz:            2016.10-py36_0
six:             1.10.0-py36_0

Proceed ([y]/n)? y

An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

https://github.com/conda/conda/issues

Current conda install:

           platform : win-32
      conda version : 4.3.11
   conda is private : False
  conda-env version : 4.3.11
conda-build version : not installed
     python version : 3.6.0.final.0
   requests version : 2.12.4
   root environment : C:ProgramDataAnaconda3  (writable)
default environment : C:ProgramDataAnaconda3envsdlnd
   envs directories : C:ProgramDataAnaconda3envs
                      C:UsersDipan AryaAppDataLocalcondacondaenvs
                      C:UsersDipan Arya.condaenvs
      package cache : C:ProgramDataAnaconda3pkgs
                      C:UsersDipan AryaAppDataLocalcondacondapkgs
       channel URLs : https://repo.continuum.io/pkgs/free/win-32
                      https://repo.continuum.io/pkgs/free/noarch
                      https://repo.continuum.io/pkgs/r/win-32
                      https://repo.continuum.io/pkgs/r/noarch
                      https://repo.continuum.io/pkgs/pro/win-32
                      https://repo.continuum.io/pkgs/pro/noarch
                      https://repo.continuum.io/pkgs/msys2/win-32
                      https://repo.continuum.io/pkgs/msys2/noarch
        config file : None
       offline mode : False
         user-agent : conda/4.3.11 requests/2.12.4 CPython/3.6.0 Windows/7 W

indows/6.1.7601

$ C:ProgramDataAnaconda3Scriptsconda-script.py install pandas

Traceback (most recent call last):
  File "C:ProgramDataAnaconda3libsite-packagescondaexceptions.py", lin

e 616, in conda_exception_handler
return_value = func(*args, **kwargs)
File «C:ProgramDataAnaconda3libsite-packagescondaclimain.py», line
137, in _main
exit_code = args.func(args, p)
File «C:ProgramDataAnaconda3libsite-packagescondaclimain_install.py
«, line 80, in execute
install(args, parser, ‘install’)
File «C:ProgramDataAnaconda3libsite-packagescondacliinstall.py», li
ne 359, in install
execute_actions(actions, index, verbose=not context.quiet)
File «C:ProgramDataAnaconda3libsite-packagescondaplan.py», line 825,
in execute_actions
execute_instructions(plan, index, verbose)
File «C:ProgramDataAnaconda3libsite-packagescondainstructions.py», l
ine 258, in execute_instructions
cmd(state, arg)
File «C:ProgramDataAnaconda3libsite-packagescondainstructions.py», l
ine 118, in UNLINKLINKTRANSACTION_CMD
txn = UnlinkLinkTransaction.create_from_dists(index, prefix, unlink_dist
s, link_dists)
File «C:ProgramDataAnaconda3libsite-packagescondacorelink.py», line
123, in create_from_dists
for dist, pkg_dir in zip(link_dists, pkg_dirs_to_link))
File «C:ProgramDataAnaconda3libsite-packagescondacorelink.py», line
123, in
for dist, pkg_dir in zip(link_dists, pkg_dirs_to_link))
File «C:ProgramDataAnaconda3libsite-packagescondagatewaysdiskread.
py», line 85, in read_package_info
index_json_record = read_index_json(extracted_package_directory)
File «C:ProgramDataAnaconda3libsite-packagescondagatewaysdiskread.
py», line 104, in read_index_json
with open(join(extracted_package_directory, ‘info’, ‘index.json’)) as fi
:
FileNotFoundError: [Errno 2] No such file or directory: ‘C:ProgramDataAn
aconda3pkgspandas-0.19.2-np111py36_1infoindex.json’

(dlnd) C:UsersDipan AryaDesktopudadlnd-your-first-networkDLND-your-first-n
etwork>

ModuleNotFoundError — No Module Named ‘Pandas’

The ModuleNotFoundError — No Module Named ‘Pandas’ error occurs because the Python interpreter can’t locate your installation of the Pandas library. The easiest solution is to make sure Pandas is installed, which you can do with the following shell commands, depending on your Python installation (either Pip or Anaconda):

  • Pip: Run pip install pandas
  • Anaconda: Run conda install pandas

However, there are more reasons why you might get ModuleNotFoundError: No Module Named ‘Pandas’, and today’s article will go through all of them.

Table of contents:


How to Install Pandas with Pip and Anaconda

The ModuleNotFoundError — No Module Named ‘Pandas’ often occurs in PyCharm, VSCode, Jupyter, or any other IDE of your choice. The tool is ultimately irrelevant because it doesn’t cause the error — it only reports the result from the Python interpreter.

We already have extensive guides on How to install Pandas and How to install Pandas Specific version, so there’s no need to go into much depth here.

Simply, if you’re using Pip, run one of the following commands to install Pandas:

# To install the latest stable version of Panas
pip install pandas

# To install a specific version of Pandas, e.g., 1.3.4
pip install pandas==1.3.4

Likewise, if you’re using Anaconda, run either of these commands:

# To install the latest stable version of Panas
conda install pandas

# To install a specific version of Pandas, e.g., 1.3.4
conda install pandas=1.3.4

These commands will work 95% of the time, but if they don’t, continue reading to find the solution.


Other Causes of ModuleNotFoundError — No Module Named ‘Pandas’

We’ll now walk you through a series of potential reasons why you’re getting the No Module Named ‘Pandas’ error. Let’s start with the first, most obvious one.

Pandas Installed in a Virtual Environment, But You’re Accessing it Globally

We have a virtual environment named pandas-env which contains the latest development version of Pandas — 2.0.0RC1. This Pandas installation is specific to that environment and isn’t accessible outside it.

Take a look at the following image to verify:

Image 1 - Pandas version installed inside a virtual environment (Image by author)

Image 1 — Pandas version installed inside a virtual environment (Image by author)

If you were to deactivate this environment and import Pandas in a global (system-wide) one, you will get a ModuleNotFoundError — No Module Named ‘Pandas’ error:

Image 2 - ModuleNotFoundError - No Module Named &lsquo;Pandas&rsquo; error (Image by author)

Image 2 — ModuleNotFoundError — No Module Named ‘Pandas’ error (Image by author)

Solution: If you install Pandas inside a virtual environment, don’t forget to activate it before working with Pandas. Failing to do so is likely to result in a ModuleNotFoundError since global Python installation doesn’t know of the Pandas dependency.

You’ve Named Your Module ‘pandas.py’

Now, doing this could return all sorts of errors, ModuleNotFoundError being one of them.

Put simply, if you name your Python module pandas or if you create a file called pandas.py, you will shadow the actual library you’re trying to import.

To demonstrate, create two files in a folder — main.py and pandas.py. The contents of pandas.py are as follows:

# pandas.py

def sum_nums(a: int, b: int) -> int:
 return a + b

And the contents of main.py are:

# main.py

import pandas as pd

print(pd.__version__)

As you can see, main.py tries to import the Pandas library and print its version, but it imports the pandas.py file since it shadows the actual library. Running main.py would result in the following error:

Image 3 - Naming a file/module pandas.py (Image by author)

Image 3 — Naming a file/module pandas.py (Image by author)

Solution: Make sure your files and folders don’t have the same name as built-in Python libraries, nor the libraries you’ve installed manually, such as Pandas.

You’ve Declared a Variable ‘pandas’ By Accident

If you import the Pandas library and then somewhere in your script assign a value to a variable named pandas, that variable will shadow the library name.

By doing so, you won’t be able to access all the properties and methods Pandas library has to offer.

Take a look at the following snippet — it imports the Pandas library and then declares a variable pandas and assigns a string to it. You can still print out the contents of the variable, but you can’t access properties and methods from the Pandas library anymore:

# main.py
import pandas

pandas = "Don't do this!"

print(pandas)
print("----------")
print(pandas.__version__)

Image 3 - Declaring a variable named &lsquo;pandas&rsquo; (Image by author)

Image 3 — Declaring a variable named ‘pandas’ (Image by author)

Solution: Be a bit more creative with how you name your variables and make sure the name is different from any module you’ve imported.


No Module Named ‘Pandas’ Q&A

We’ll now go over some frequently asked questions about ModuleNotFoundError: No Module Named ‘Pandas’ error and the common solutions for them.

Q: How Do I Fix No Module Named Pandas?

A: First, make sure that Pandas is installed. Do so by running either pip install pandas or conda install pandas, depending on your environment. If that doesn’t work, try reinstalling Pandas by running the following sets of commands:

Pip:

pip uninstall pandas
pip install pandas

Anaconda:

conda uninstall pandas
conda install pandas

If neither of those works, make sure you don’t have a file/folder named pandas or pandas.py in your project’s directory, and make sure you haven’t named a variable pandas after importing the library.

Q: Why is it Showing No Module Named Pandas?

A: In case you’re using an IDE such as PyCharm, VSCode, or Jupyter, it’s possible the IDE is not recognizing your Python environment. Make sure the appropriate Python kernel is selected first.

A solution to ModuleNotFoundError — No Module Named ‘Pandas’ VSCode (Visual Studio Code):

Image 5 - VSCode solution (Image by author)

Image 5 — VSCode solution (Image by author)

A solution to PyCharm ModuleNotFoundError — No Module Named ‘Pandas’:

Image 6 - PyCharm solution (Image by author)

Image 6 — PyCharm solution (Image by author)

Q: Why I Can’t Install Pandas in Python?

A: One likely reason you can’t install Pandas in Python is that you don’t have administrative privileges on your system. For example, maybe you’re using a work or college computer and trying to install Pandas there. That system will likely be protected and it won’t allow you to install anything, Python modules included.

Another potential reason is that you’re maybe behind a corporate firewall. Before installing Pandas, configure the firewall settings manually to allow outgoing connections to the Internet, or talk to a company specialist.

Q: How Do I Know if Pandas is Installed?

A: You can verify if Pandas is installed on your system by opening up a Python interpreter and running the following code:

import pandas as pd

pd.__version__

If you don’t see any errors after the library import and if you see the version printed, then you have Pandas installed. Congratulations!

Here’s an example of what you should see:

Image 7 - Pandas installation check (Image by author)

Image 7 — Pandas installation check (Image by author)


Summing up

And there you have it, a list of many, many ways to install Pandas, and many potential issues and solutions you might encounter. As always, there’s no one-size-fits-all solution, but you’re more than likely to find an answer to ModuleNotFoundError: No Module Named ‘Pandas’ in this article.

Likely, you don’t have the library installed, but if that’s not the case, one of the other explained solutions is almost guaranteed to do the trick.

We hope you’ve managed to install Pandas properly, and can’t wait to see you in the following article.

Recommended reads

  • Top 10 Books to Learn Pandas in 2023 and Beyond

Активировал env
conda activate ./env

Установил Pandas
conda install pandas

Запускаю файл
import pandas as pnd

Выходит ошибка

Exception has occurred: ModuleNotFoundError
No module named 'pandas'

Коллеги, как это починить?

python -V      
Python 3.8.5

conda info
     active environment : /Users/a/eduсation/m/project_1/env
    active env location : /Users/a/eduсation/m/project_1/env
            shell level : 2
       user config file : /Users/a/.condarc
 populated config files : 
          conda version : 4.9.1
    conda-build version : not installed
         python version : 3.8.3.final.0
virtual packages : __osx=10.15.7=0
                          __unix=0=0
                          __archspec=1=x86_64

  • Conansandbox exe ошибка приложения
  • Conan exiles ошибка идентификации при подключении
  • Conan exiles ошибка идентификации на пиратке
  • Conan exiles ошибка ue4
  • Conan exiles battleye ошибка