I have some trouble to document my Cython (python 2.7) module with Sphinx (1.7).
I set the Cython directive embedsignature to True, and I also mock numpy in my conf.py file. However, if I run sphinx-build -b html source build I get the following TypeError:
WARNING: autodoc: failed to import module u'isolver'; the following exception was raised:
Traceback (most recent call last):
File "C:\Users\xxx\Anaconda2\lib\site-packages\sphinx\ext\autodoc\importer.py", line 140, in import_module
__import__(modname)
File "c:\users\xxx\dropbox\github\isolver\isolver\__init__.py", line 1, in <module>
import core
File "c:\users\xxx\dropbox\github\isolver\isolver\core\__init__.py", line 1, in <module>
import c_trf
File "__init__.pxd", line 155, in init isolver.core.c_trf
TypeError: numpy.dtype is not a type object
The weird thing is I do not have a *.pxd file and line 155 in c_trf.pyx file is empty.
Perhaps the secret of this error lies in the way how I declared the numpy data types?
cimport numpy as np
import numpy as np
DTYPE_int = np.int64
ctypedef np.int64_t DTYPE_int_t
DTYPE_float = np.float64
ctypedef np.float64_t DTYPE_float_t
Or maybe the declarations of some functions with cdef np.ndarray fun(x):... are wrong?
Related
Using cmd on windows 10 to run Python 2.7.16. When I run a .py file which imports scipy.py it comes up with the error:
"File "C:\Python27\scipy.py", line 18, in
from .python import string_types
ValueError: Attempted relative import in non-package"
As string_types should already be included in python, I don't understand why this error is happening and cant seem to get passed it. Does anyone know how to fix this?
you tried,
>>> from . import MyModule #MyModule.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
>>>
here . mean your current path
try,
from MyModule import *
now you can use string_types
or
import MyModule as m
m.string_types
I found a problem in the python program.I don't know what I have to do.
Cordially.
import pyautogui
im1 = pyautogui.screenshot()
im2 = pyautogui.screenshot('my_screenshot.png')
Traceback (most recent call last):
File "C:/Users/LENOVO/Desktop/yyyu.py", line 1, in <module>
import pyautogui
File "C:\Python27\lib\site-packages\pyautogui\__init__.py", line 84, in <module>
import pyscreeze
SyntaxError: 'return' with argument inside generator (__init__.py, line 168)
You probably get this error because you use python 2, try to use python 3
I am using Scipy.stats to perform distribution fits on my data. It works perfectly on my machine. But when I package my script with Python source folder, python27.dll and try to run it on another machine (where python is not installed and I do not want to also) by invoking my script like below
Path/to/Python.exe Path/to/script.py
I get the follwing error
Traceback (most recent call last):
File "test2.py", line 2, in <module>
import scipy.stats
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\__init__.py
", line 344, in <module>
from .stats import *
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\stats.py",
line 173, in <module>
import scipy.special as special
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\special\__init__.
py", line 636, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
My script is
import sys
import scipy.stats
import numpy
dataarray= [2.45, 3.67, 1.90, 2.56, 1.78, 2.67]
desc = scipy.stats.describe(dataarray)
print desc
This occurs only on Scipy import and scipy operations, all other imports and operations work fine. My purpose is to run this script in different machines without having to actually install python
I am new to python and I am trying to work on a project with deep learning and want to use graphlab library. I use sublime text for coding on windows 10. My code is only this line:
import graphlab
I get this error msg:
Traceback (most recent call last):
File "test.py", line 1, in
import graphlab
File "graphlab__init__.py", line 59, in
from graphlab.data_structures.sgraph import Vertex, Edge
File "graphlab\data_structures__init__.py", line 25, in
from . import sframe
File "graphlab\data_structures\sframe.py", line 19, in
from ..connect import main as glconnect
File "graphlab\connect\main.py", line 26, in
from ..cython.cy_unity import UnityGlobalProxy
ImportError: No module named cy_unity
Try using graphlab.get_dependencies() in your interpreter.
I think I made a mistake when installing, i re-installed and it worked fine. Thanks anyway
Using Anaconda 2.5.0 (python 2.7) on a relatively clean Ubuntu 15.04 desktop system, I have the following unusual behavior:
If I package my application with cx_Freeze 4.3.4 and add the bin directory to the PYTHONPATH environment variable:
export PYTHONPATH=~/frozen-app/bin
Then, when I mistype a bash command:
sl
Instead of the expected:
The program 'sl' is currently not installed. You can install it by typing:
sudo apt-get install sl
I get a python stack trace:
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 23, in <module>
import gettext
File "/usr/lib/python3.4/gettext.py", line 49, in <module>
import locale, copy, io, os, re, struct, sys
File "/usr/lib/python3.4/locale.py", line 18, in <module>
import collections
File "/usr/lib/python3.4/collections/__init__.py", line 11, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: dynamic module does not define init function (PyInit_operator)
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 62, in apport_excepthook
import re, traceback
File "/usr/lib/python3.4/traceback.py", line 3, in <module>
import linecache
File "/usr/lib/python3.4/linecache.py", line 10, in <module>
import tokenize
File "/usr/lib/python3.4/tokenize.py", line 29, in <module>
import collections
File "/usr/lib/python3.4/collections/__init__.py", line 11, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: dynamic module does not define init function (PyInit_operator)
Original exception was:
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 23, in <module>
import gettext
File "/usr/lib/python3.4/gettext.py", line 49, in <module>
import locale, copy, io, os, re, struct, sys
File "/usr/lib/python3.4/locale.py", line 18, in <module>
import collections
File "/usr/lib/python3.4/collections/__init__.py", line 11, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: dynamic module does not define init function (PyInit_operator)
It seems that the "command-not-found" command gets confused by my PYTHONPATH environment, but I can't figure out exactly why. I don't think any of the mentioned modules are defined in my application (I don't define an "re" module in my app for example).
If I run "strace sl", then I just get "can't stat sl". Is there another way to figure out exactly which file in my application is causing this?
Using the suggestion by Charles Duffy above, and looking more closely at the python stack trace, I was able to reproduce the error with:
python3.4 -m operator
Just this replicates the stack trace. Since my PYTHONPATH points to a bin directory from from an Anaconda2.5 (python 2.7), it seems that the python3.4 tries to load operator.so from the the anaconda distribution which has been frozen in my bin directory. This particular import fails. Deleting operator.so from my bin fixes this issue. It seems that using the system python3.4 (which is used by command-not-found) and the Anaconda 2.7 combined with explicitly setting PYTHONPATH can cause trouble.