I am having trouble importing modules in python 2.7.13. I run the python script and this is the following error.
Traceback (most recent call last):
File "server.py", line 3, in <module>
import pandas as pd
ImportError: No module named pandas
This is the case for any other modules that I need to import, not just pandas.
pip list:
numexpr (2.2.2)
numpy (1.8.2)
oauth (1.0.1)
openpyxl (1.7.0)
PAM (0.4.2)
pandas (0.13.1)
python-apt (0.9.3.5ubuntu2)
python-dateutil (1.5)
python-debian (0.1.21-nmu2ubuntu2)
pytz (2012rc0)
PyYAML (3.10)
requestbuilder (0.1.0b1)
requests (2.2.1)
scipy (0.13.3)
xlrd (0.9.2)
xlwt (0.7.5)
python -V:
Python 2.7.13
pip -V:
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
This problem happened because I just had upgraded my python from 2.7.6 to 2.7.13. I will only be working with 2.7.13, so no need to set up virtualenv for different python versions.
Related
Whenever I run the command python3.6 Check.py, I get the following error,
Pandas Error
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pandas/init.py", line 30, in
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
File "/usr/lib/python3/dist-packages/pandas/_libs/init.py", line 3, in
from .tslibs import (
File "/usr/lib/python3/dist-packages/pandas/_libs/tslibs/init.py", line 3, in
from .conversion import localize_pydatetime, normalize_date
ModuleNotFoundError: No module named 'pandas._libs.tslibs.conversion'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Check.py", line 2, in
import pandas as pd
File "/usr/lib/python3/dist-packages/pandas/init.py", line 38, in
"the C extensions first.".format(module)
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I quickly google the error and find this link: No module named 'pandas._libs.tslib'
I uninstall pandas:
uninstall message
Found existing installation: pandas 1.3.3
Uninstalling pandas-1.3.3:
Would remove:
/u/riker/u97/pmohanty/.local/lib/python3.8/site-packages/pandas-1.3.3.dist-info/*
/u/riker/u97/pmohanty/.local/lib/python3.8/site-packages/pandas/*
Proceed (y/n)? y
Successfully uninstalled pandas-1.3.3
I reinstall it:
reinstall message
Requirement already satisfied: pandas in /usr/lib/python3/dist-packages (0.25.3)
I upgrade it too:
upgrade message
Collecting pandas
Using cached pandas-1.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB)
Requirement already satisfied, skipping upgrade: numpy>=1.17.3 in /u/riker/u97/pmohanty/.local/lib/python3.8/site-packages (from pandas) (1.21.2)
Requirement already satisfied, skipping upgrade: pytz>=2017.3 in /u/riker/u97/pmohanty/.local/lib/python3.8/site-packages (from pandas) (2021.1)
Requirement already satisfied, skipping upgrade: python-dateutil>=2.7.3 in /u/riker/u97/pmohanty/.local/lib/python3.8/site-packages (from pandas) (2.8.2)
Requirement already satisfied, skipping upgrade: six>=1.5 in /u/riker/u97/pmohanty/.local/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.16.0)
Installing collected packages: pandas
Successfully installed pandas-1.3.3
Despite following the steps my file won't run.
Strangely it works for python3, python3.8, but not for python3.6.
python3 --version outputs 3.8.10
python3.6 --version outputs 3.6.9
pip --version outputs pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
I am new to python and pandas and stackoverflow. Any help is appreciated.
PS: I need to get it to work in 3.6 :'(
If you really need it to work in python 3.6, you need to install it for python 3.6:
python3.6 -m pip install pandas
See e.g. this article for a discussion of why this works.
I have to run a python 3 script on a centos 7 host. I've installed python3.8 side by side with python2 so it doesn't break yum.
When I'm running the script I need to run I get this error:
Traceback (most recent call last):
File "A2PTestSuit.py", line 8, in <module>
import pandas as pd
File "/usr/local/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy: No module named '_ctypes'
If I list the modules I see that pandas and numpy are installed:
python3 -m pip list
Package Version
--------------- ----------
certifi 2019.11.28
chardet 3.0.4
DateTime 4.3
idna 2.8
numpy 1.18.1
pandas 0.25.3
pip 19.3.1
python-dateutil 2.8.1
pytz 2019.3
requests 2.22.0
setuptools 41.2.0
six 1.13.0
urllib3 1.25.7
zope.interface 4.7.1
How can I get past this error?
You can try updating all of your packages in the command line using pip, or just use try: import ... except ImportError: continue
I've got same issue. Problem was solved after I change default interpreter (which was Python 3.8) in PyCharm
I’m having trouble with installation of (or is it usage of?!) the beautifulsoup4 package, with Python 3.6, on MacOS High Sierra (10.3). I experienced the problem first in PyCharm and then also had same issue from the MacOS terminal, as demonstrated below. I’ve searched high and low on Stackoverflow and on the web at large, but cannot find a post/explaination that seems to meet the very specific symptoms I’m experiencing.
First three lines of my Python 3 code file called “main.py”….
import numpy as np
import matplotlib.pyplot as plt
import beautifulsoup4 as bs
When I execute it, I get the following error, seemingly indicating that the beautifulsoup4 package is not installed…..
DangerZone:test09-playwithnumpyandscipy bruce$ python3 main.py
Traceback (most recent call last):
File "main.py", line 3, in <module>
import beautifulsoup4 as bs
ModuleNotFoundError: No module named 'beautifulsoup4'
Yet, when I request a "list" of installed modules from pip3, i get the following....
DangerZone:test09-playwithnumpyandscipy bruce$ pip3 list
beautifulsoup4 (4.6.0)
certifi (2017.7.27.1)
chardet (3.0.4)
cycler (0.10.0)
idna (2.5)
inflection (0.3.1)
matplotlib (2.0.2)
more-itertools (3.2.0)
numpy (1.13.1)
pandas (0.20.3)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.1)
pytz (2017.2)
Quandl (3.2.0)
requests (2.17.3)
scikit-learn (0.19.0)
scipy (0.19.1)
setuptools (28.8.0)
six (1.10.0)
sklearn (0.0)
urllib3 (1.21.1)
Seems that beautifulsoup4 is installed, so why the earlier error? What am I doing wrong?
I've always found this one a bit weird, because the name of the library is 'BeautifulSoup4'. However, the proper way to import it is:
from bs4 import BeautifulSoup as bs
Making the Soup (documentation)
I have installed pyOpenSSL and all the required packages but i can't import OpenSSL in the shell . I get this error :
>>> import OpenSSL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named OpenSSL
list of required packages that are allready installed:
cryptography (0.9.3)
distribute (0.7.3)
idna (2.0)
pip (7.1.0)
pyasn1 (0.1.8)
pyasn1-modules (0.0.5)
pyopenssl (0.15.1)
requests (2.7.0)
service-identity (14.0.0)
setuptools (18.1)
six (1.9.0)
Twisted (15.2.1)
urllib3 (1.11)
w3lib (1.12.0)
zope.interface (4.1.2)
If you are running a 64-bit version of Windows then I recommend you install a Win64 version of OpenSSL, available from https://slproweb.com/products/Win32OpenSSL.html (scroll down until you find the 64 bit installers) and the 64-bit version of pyOpenSSL, available from http://www.egenix.com/products/python/pyOpenSSL/
Check that you don't have 32-bit versions of the various products, python-packages, etc. I had some site-packages on the PYTHONPATH which confused python. I removed the environment variable PYTHONPATH and similarly PYTHONUSERBASE (both were recommended by some software I was trying where they wanted to use 32-bit versions of mitmproxy and working backwards everything else...) I want to retain my 64-bit version of Python (2.7.6) hence my struggles as I ran into the same error you reported here.
I've run into the issue that when I import the requests module in iPython it works great however when I try to compile a file that uses it everything goes bananas. Similarly when I try to import requests in the standard python interpreter things go bananas as well.
Any ideas?
import csv, requests, re
Leads to
Traceback (most recent call last):
File "sherpa_romeo.py", line 18, in <module>
import csv, requests, re
ImportError: No module named requests
I'm thinking that I may have pip'd to the wrong version of python.
I installed with the command:
pip install requests
I ran the command pip list and it returned:
certifi (14.05.14)
Flask (0.10.1)
gnureadline (6.3.3)
ipython (2.4.1)
itsdangerous (0.24)
Jinja2 (2.7.3)
MarkupSafe (0.23)
oauthlib (0.6.3)
pip (1.5.6)
pokitdok (0.9)
requests (2.4.0)
requests-oauthlib (0.4.1)
sendgrid (1.1.0)
setuptools (5.4.2)
smtpapi (0.1.2)
unittest2 (0.5.1)
virtualenv (1.11.6)
Werkzeug (0.9.6)
wsgiref (0.1.2)
which includes requests so I'm confused on why it's not working.
In the directory where you have the file that you compile, see if there is another file named "requests" and rename it