I am trying to run following simple script on Debian Stable Linux:
$ cat ./mytest.py
#! /usr/bin/python3
print("Before importing sys.")
import sys
print("Before importing pandas.")
import pandas as pd
print("Before importing numpy.")
import numpy as np
But it is giving following error:
$ ./mytest.py
Before importing sys.
Before importing pandas.
time.struct_time(tm_year=2017, tm_mon=11, tm_mday=22, tm_hour=22, tm_min=43, tm_sec=50, tm_wday=2, tm_yday=326, tm_isdst=0)
Date=22
Month=11
Year=2017
Hour=22
Minute=43
Second=50
Local current time : Wed Nov 22 22:43:50 2017
Traceback (most recent call last):
File "./mytest.py", line 7, in <module>
import pandas as pd
File "/usr/lib/python3/dist-packages/pandas/__init__.py", line 13, in <module>
__import__(dependency)
File "/home/iuser/.local/lib/python3.5/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/home/iuser/.local/lib/python3.5/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/home/iuser/.local/lib/python3.5/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/home/iuser/.local/lib/python3.5/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/home/iuser/.local/lib/python3.5/site-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
SystemError: initialization of multiarray raised unreported exception
Following versions of pandas and numpy are installed through Debian Repositories:
Package Installed Previous Now State
=======================-===============-===============-===============-=====
python3-pandas 0.19.2-5.1 0.19.2-5.1 0.19.2-5.1 install
python3-pandas-lib 0.19.2-5.1 0.19.2-5.1 0.19.2-5.1 install
python-numpy 1:1.12.1-3 1:1.12.1-3 1:1.12.1-3 install
python3-numpy 1:1.12.1-3 1:1.12.1-3 1:1.12.1-3 install
Where is the problem and how can it be solved?
Edit: I find that the same above file works perfectly in another folder! I am using correct filename for command.
$ ./mytest.py
Before importing sys.
Before importing pandas.
Before importing numpy.
There are other files and sub-folders in first folder. One of which is __pycache__
which contains following files:
$ ls
datetime.cpython-35.pyc myfns.cpython-35.pyc myframe.cpython-35.pyc
My datetime.py file has following:
import time
tt = time.localtime()
print(tt)
print("Date="+str(tt.tm_mday))
print("Month="+str(tt.tm_mon))
print("Year="+str(tt.tm_year))
print("Hour="+str(tt.tm_hour))
print("Minute="+str(tt.tm_min))
print("Second="+str(tt.tm_sec))
localtime = time.asctime( time.localtime() ) # <<<<<<<<<<<<<<<<<< same as complex above;
print ("Local current time :", localtime)
Is it possible these are interfering?
Advertisement
Answer
Since the script was working well in other folders, the problem was in this folder only. There was a file named datetime.py
in this folder, removal of which resolved the problem. Apparently, pandas
looks for a file named datetime.py
and searches first the current folder, where it finds this user file with same name. Hence the problem.
Moral of the story: User files should not be given general names that may be being used by software packages.