I'm running Python 3.6.4, and am getting an import error from pandas. I'm installing it with 'pip install pandas' (which installs version 0.22). Installing it seems to go fine, but when I try to import it, an error gets thrown:
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python36\lib\site-packages\pandas\__init__.py", line 13, in <module>
__import__(dependency)
File "C:\Python36\lib\site-packages\pytz\__init__.py", line 32, in <module>
from pytz.lazy import LazyDict, LazyList, LazySet
File "C:\Python36\lib\site-packages\pytz\lazy.py", line 3, in <module>
from UserDict import DictMixin
File "C:\Python36\lib\UserDict.py", line 167
raise TypeError, "pop expected at most 2 arguments, got "\
Any help is much appreciated! Thank you!!
Edit:
Stephen pointed out that the root problem is pytz failing to import. Importing anything form pytz throws the same error. I've found one reference to the same error (http://www.smashcompany.com/technology/weird-that-under-python-3-4-runtime-you-can-import-from-2-7), which suggested an old path variable was the problem. I don't see any outdated python variables in my PATH, however.
Unless you use a virtual environment, pip usually corresponds to Python 2.x. The convention is to use pip3 to refer to the pip binary for Python 3.x. Since you are using 3.6.4, pip may be installing pandas for the wrong version of Python. You can confirm if it's using the correct one with
pip --version
If it says that it's using an interpreter other than the one you are using to run your code, try using
pip3 install pandas
instead.
I didn't figure out what caused the problem, but I was able to fix this by manually deleting all of the python files and directories still left behind after uninstalling python (not sure if it is normal that files were left at all) and then doing a completely fresh install.
There were no import problems after a 100% fresh install. Something must have gotten messed up, and running the default 'repair' or 'uninstall' and 'install' through the python installer (of multiple versions) wasn't correcting it.
Related
I'm quite new to programming and I am struggling with package installation. I am trying to utilize the hyriver/pynhd package from github https://github.com/hyriver/pynhd. I am using PythonWin 3.7.11 [MSC v.1927 64 bit (AMD64)] on win32. I am trying to access the pynhd package by using import pynhd as nhd. However, when I try to run it, it says:
Traceback (most recent call last):
File "C:\pynhd-main\tests\test_pynhd.py", line 10, in <module>
import pynhd as nhd
File "C:\pynhd-main\pynhd\pynhd.py", line 4, in <module>
import async_retriever as ar
ModuleNotFoundError: No module named 'async_retriever'
I thought that I had successfully installed async_retriever through the python cmd prompt on my computer but it still is not found. To install async_retriever I used pip install async_retriever. Might anyone have any suggestions?
My end goal is to utilize the HyRiver application in conjunction with ArcGIS.
I compiled python3.8 on a half dozen servers (SUSE Linux) and it is working fine on most of them.
But on one, it throws this weird error when I try to install and use the cx_Oracle library.
I set up a virtual environment, and pip install cx_Oracle (version 8.0.0). The installation works fine, but then when I try to import cx_Oracle, it throws an error:
[GCC 4.8.5] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_cx_Oracle)
>>>
Not sure what to look for here. Any thoughts on what the problem might be, or how to trace this out?
Fixed! It turned out there was a PYTHONPATH environment variable active that was pointing to the old Python 2.7 folders, even though I was in a Python 3.8 virtual environment. After deleting that environment variable, it started working.
More info with how we diagnosed it here:
https://github.com/oracle/python-cx_Oracle/issues/464
I am using Python 3.x and a virtualenv -- not conda, just a plain virtualenv.
I activate the venv and run pip install opencv-python. However,
import cv2 gives me a DLL not found error:
(tf) C:\>python
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\src\venv\tf\lib\site-packages\cv2\__init__.py", line 4, in <module>
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
>>>
Is this a virtualenv bug? How do I figure out which module/dll is missing?
On resolving "module could not be found" errors in general
Try using either Microsoft's Dependency Walker or lucasg's Dependencies on the module being loaded. Be sure to run Dependencies.exe from your virtualenv's command prompt, so it picks up your modified PATH.
The import line is from .cv2 import *, so the module being loaded is in the same directory as __init__.py (this is the leading .) and named cv2-SOMETHING.pyd (this is what native Python modules look like). Load that file into Dependencies.exe and it will show you the DLL that Windows wants but can't find.
In this case, the DLL is Python3.dll. Why is it missing? Because of a virtualenv bug that is fixed, but hasn't made its way into a release -- there hasn't been a release in more than a year.
On resolving this issue in particular
The github issue suggests a fix: use venv.
Alternatively you can copy the missing python3.dll into your virtualenv by hand. You'll have to do this for every virtualenv you create.
copy "c:\Program Files\Python36\python3.dll" "c:\src\venv\tf\Scripts\"
Using Python 2.7.3 with Numpy 1.6.2 on a 64-bit Ubuntu 12.04. Additional versions are present on the system (Python 2.6.4 and Numpy 1.6.1) but to the best of my knowledge these have no influence on the events described below.
I'm working on a Python program which uses Numpy, and getting an error when I try to run a certain command from the program. So, I decided to install python2.7-dbg to run the program with it and see if that can help with debugging. So I run
$ python-dbg <command>
instead of
$ python <command>
However, this gives an "undefined symbol: Py_InitModule4_64" error related to numpy. It doesn't matter what exactly I try to run; the error also occurs for commands that succeed if run with the "regular" python. It occurs even if I try to import numpy into a blank python-dbg prompt:
$ python-dbg
Python 2.7.3 (default, Aug 1 2012, 04:55:00)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/dist-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: Py_InitModule4_64
[134187 refs]
>>>
Importing numpy succeeds when in a pure python prompt.
I've had no luck finding information on the internet. The closest match to my error is this bug on debian which is the exact same situation but has been closed before any further information was provided. I've installed both the python-numpy-dbg and the python-apt-dbg packages from APT; I have sudo access to the machine so the changes I make are valid system-wide. As far as I know, no chroot options have been set for any of the processes I'm trying to run, so the Debian bug page is of no help to me.
Any assistance will be greatly appreciated.
As confirmed by the OP, the clue here is in the traceback which shows that numpy you're importing is in /usr/local/lib/. However, packages installed by apt go into /usr/lib/pythonX.Y, where as non-Ubuntu Python packages installed with pip, easy_install, etc. are installed under /usr/local/lib/pythonX.Y and supersedes the system packages.
For now you should uninstall the Numpy you have installed under /usr/local/lib/python2.7/dist-packages in order for the one installed by python-numpy to work. In the future you might be able to have both installed and do something with usercustomize.py to switch between them, but I'm not on an Ubuntu machine right now so I have no way of testing that out.
I can't seem to import the email module at all. Every time I do it I get an error. I've tried uninstalling Python and reinstalling, but the email module just refuses to work. I've even done "pip install email" and it's still broken. I'm on Windows 7 Home Premium x64, running an x86 version of Python.
Here's what happens:
c:\Users\Nicholas\Desktop>python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import email
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "email.py", line 1, in <module>
import smtplib
File "C:\Python27\lib\smtplib.py", line 46, in <module>
import email.utils
ImportError: No module named utils
>>>
EDIT: I've tried both Python from python.org and ActivePython, thinking ActivePython might work. Is there anyway to completely remove python and all its data and start 100% fresh maybe?
It looks like you have a file named email.py. Don't use file names that have the same name as Python standard library modules. Generally, your working directory comes earlier on the Python search path for importing modules so files in your working directory will override modules with the same name in the standard library.
The clue: note the path names in the traceback
File "email.py", line 1, in <module>
import smtplib
File "C:\Python27\lib\smtplib.py", line 46, in <module>
import email.utils
By the way, this is a very common error. The excellent tutorial in the Python standard documentation set talks about it here.
I just came across this error and wanted to share my solution. In my case, I had a file named email.py in directory. This created a name conflict between Python's email.py and my file. When smtplib tried to import email.utils it looked and my file and didn't find anything. After I renamed my copy of email.py into myemail.py everything worked like a charm.
I also came across this error. In addition to renaming the email.py to something else, you must also remove the email.pyc (notice the C) file. After that, all is well. Thanks all!
I also fetched this problem because i had a file named email.py in my project directory. I wasn't able to import urllib.request . When i changed the file name email.py to emailtest.py then the error gone away.
In every time we should not use the name what is same as python core file name.
If none of the posted solution works, try the following:
(Use the combo python3 / pip3 OR python / pip and try not to mix those)
Delete your current virtual environment directory.
Create new virtual environment and activate it with 'source'.
If exist, run the <pip install -r requirements.txt>.
Install any missing packages with pip or pip3.
Run the application to see if that solved the problem.
npm install email
has fix my problem, try it.