This is an odd problem. I have Python script which imports numpy and matplotlib.
If I put those scripts into /usr/local/bin, I can load the modules and run my scripts with no problem.
But if I have those scripts in my "work" directory, I get errors.
This is also true if I use python in interactive mode:
$ pwd
/usr/local/bin
$ python
Python 2.7.12 (default, Oct 10 2016, 12:56:26)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import matplotlib
>>>
No problems.
However, if I go to my work directory, I have problems:
$ pwd
/home/Administrator/Documents/Projects/MOCC/rads
$ python
Python 2.7.12 (default, Oct 10 2016, 12:56:26)
[GCC 5.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/site-packages/numpy/core/__init__.py", line 46, in <module>
from numpy.testing import Tester
File "/usr/lib/python2.7/site-packages/numpy/testing/__init__.py", line 13, in <module>
from .utils import *
File "/usr/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
from tempfile import mkdtemp
File "/usr/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "/cygdrive/c/Users/Administrator/Documents/Projects/MOCC/rads/io.py", line 63, in <module>
SEEK_CUR = 1
File "/cygdrive/c/Users/Administrator/Documents/Projects/MOCC/rads/io.py", line 58, in main
AttributeError: 'module' object has no attribute 'loadtxt'
This is cygwin on MS Windows.
Related
When I try to import Marionette driver in Python, I get this response:
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from marionette import Marionette
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/marionette_client-2.0.0-py2.7.egg/marionette/__init__.py", line 7, in <module>
from .marionette_test import (
File "/usr/local/lib/python2.7/dist-packages/marionette_client-2.0.0-py2.7.egg/marionette/marionette_test.py", line 18, in <module>
from marionette_driver.errors import (
File "/usr/local/lib/python2.7/dist-packages/marionette_driver-1.1.1-py2.7.egg/marionette_driver/__init__.py", line 7, in <module>
from marionette_driver import (
File "/usr/local/lib/python2.7/dist-packages/marionette_driver-1.1.1-py2.7.egg/marionette_driver/expected.py", line 8, in <module>
from marionette import HTMLElement
File "/usr/local/lib/python2.7/dist-packages/marionette_driver-1.1.1-py2.7.egg/marionette_driver/marionette.py", line 20, in <module>
from mozrunner import B2GEmulatorRunner
ImportError: cannot import name B2GEmulatorRunner
>>>
I have the Mozrunner package installed, but it does not have any B2GEmulatorRunner. Any suggestion as to what is causing this issue and how I can resolve this?
Edit:
After updating my entire Python 2.7 library with PIP, now I am stuck with this issue:
>>> import marionette
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/marionette/__init__.py", line 7, in <module>
from .marionette_test import (
ImportError: No module named marionette_test
I have installed TensorFlow and wanted to check the installation. Here is the interaction with the python console.
Python 2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 106, in <module>
from tensorflow.python.platform import test
File "/home/shehab1/.local/lib/python2.7/site-packages/tensorflow/python/platform/test.py", line 81, in <module>
import mock # pylint: disable=g-import-not-at-top,unused-import
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/home/shehab1/.local/lib/python2.7/site-packages/mock/mock.py", line 81, in <module>
inspectsignature = funcsigs.signature
AttributeError: 'module' object has no attribute 'signature'
>>>
Could anyone please tell what I am doing wrong? Thanks.
As Yaroslav noted, this is most likely from running too old a version of Python, or you don't have the funcsigs package installed. For the latter, try pip install funcsigs
bash-4.1$ airflow initdb
Traceback (most recent call last):
File "/u/bin/airflow", line 4, in <module>
from airflow import configuration
File "/u/lib/python2.7/site-packages/airflow/__init__.py", line 31, in <module>
from airflow.models import DAG
File "/u/lib/python2.7/site-packages/airflow/models.py", line 53, in <module>
from croniter import croniter
File "/u/lib/python2.7/site-packages/croniter/__init__.py", line 3, in <module>
from .croniter import croniter
File "/u/lib/python2.7/site-packages/croniter/croniter.py", line 8, in <module>
from dateutil.relativedelta import relativedelta
File "build/bdist.linux-x86_64/egg/dateutil/relativedelta.py", line 5, in <module>
ImportError: cannot import name integer_types
But no issues in interpreter:
bash-4.1$ /u/bin/python2.7
Python 2.7.5 (default, Oct 17 2013, 14:04:34)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import croniter
>>>
I am assuming it has to do something with:
File "build/bdist.linux-x86_64/egg/dateutil/relativedelta.py", line 5, in <module>
So in interpreter it Is using dateutil from /u/lib/python2.7 whereas in airflow it's using datutil from build/bdist.linux-x86_64/egg/dateutil??
I don't even know where build/bdist.linux-x86_64/egg/dateutil is.
Can someone tell me what's going on and how to tell airflow to import from correct dateutil?
You need to install Six python package.
Just make a pip install six
In a newly created terminal, I can import matplotlib with no error. After working for some time in the terminal, however, the following happens:
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Usage: example.py torrentfile.torrent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py", line 134, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/colors.py", line 54, in <module>
import matplotlib.cbook as cbook
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/cbook.py", line 15, in <module>
import new
File "new.py", line 12, in <module>
with open(sys.argv[1], 'rb') as fh:
IndexError: list index out of range
What's wrong?
With the help of #CaptainMurphy and #IronManMark20, I discovered new.py and new.pyc under ~/temp, which shadows some matplotlib files. After removing them, the problem is solved.
I managed to break one of my virtual environments. I think I did it by installing pycrypto with pip and uninstalling it with easy_install.
This is what I get when I run python in the venv.
filip#dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$ python
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 49, in <module>
import posixpath as path
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 17, in <module>
import warnings
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/warnings.py", line 8, in <module>
import types
File "types.py", line 1, in <module>
import json
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 3, in <module>
import re
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 280, in <module>
import copy_reg
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 7, in <module>
from types import ClassType as _ClassType
ImportError: cannot import name ClassType
filip#dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$
And outside the venv everything works as expected:
Last login: Tue Apr 7 22:30:08 on ttys005
filip#dratmac:~$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How can I fix this?
You should not name your file types.py as there is a standard library module with the same name (import types).
As such, Python tries to import it as part of some standard library code but it now actually imports your local types.py file, not the module it expects.
So the problem should be fixed when you rename types.py to something else.