'How to import pandas for python3?
I have a python script that uses pandas library. But when I try to install pandas using:
pip install pandas
It says:
Installing collected packages: pytz, six, python-dateutil, numpy, pandas
Successfully installed numpy-1.14.5 pandas-0.23.3 python-dateutil-2.7.3 pytz-2018.5 six-1.11.0
You are using pip version 8.1.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command
When I try to run my script again, it tells again that no module named pandas.
Traceback (most recent call last):
File "test.py", line 6, in <module>
import pandas as pd
ImportError: No module named 'pandas'
After using the suggestion, I tried again pip install pandas but i get an error
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
Solution 1:[1]
I suggest a workaround while someone points out a definitive solution for your dependency hell: use a virtual environment.
Using miniconda, download your package, install it and:
conda create -n py37 anaconda python=3.7
source activate py37
pip install pandas
Solution 2:[2]
If you're using the command line, make sure you execute the script using python3 (instead of python), e.g.
python3 filename.py
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JMC |
| Solution 2 | BrokenBenchmark |
