I have a some python packages code with C and Cython extensions. When i try to build them, i get an ImportError. For example, output for opensource package pydatastructs (https://github.com/codezonediitj/pydatastructs).
C:\Users\Me\Projects\pydatastructs> py setup.py build_ext --inplace
Traceback (most recent call last):
File "C:\Users\Max\Projects\pydatastructs\setup.py", line 2, in <module>
from pydatastructs import linear_data_structures
File "C:\Users\Max\Projects\pydatastructs\pydatastructs\__init__.py", line 1, in <module>
from .linear_data_structures import *
File "C:\Users\Max\Projects\pydatastructs\pydatastructs\linear_data_structures\__init__.py", line 3, in <module>
from . import (
File "C:\Users\Max\Projects\pydatastructs\pydatastructs\linear_data_structures\arrays.py", line 4, in <module>
from pydatastructs.linear_data_structures._backend.cpp import _arrays
ImportError: cannot import name '_arrays' from 'pydatastructs.linear_data_structures._backend.cpp' (C:\Users\Max\Projects\pydatastructs\pydatastructs\linear_data_structures\_backend\cpp\__init__.py)
I guess python tries to import module which is not built yet, but i can't build them.
I tried to use pip install . but output is the same as above. It is possible to comment all import from extensions then build them and it works but this approach is very inconvenient especially in large projects with many extensions.
Related
I have been trying to find a solution to this import error regarding the pandas library when it says no module named "parsing." Every library should be installed correctly from the interpreter and they are all the latest version.
This is what the console returns:
Traceback (most recent call last):
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\__init__.py", line 26, in <module>
from pandas._libs import (hashtable as _hashtable,
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\_libs\__init__.py", line 4, in <module>
from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
File "pandas\_libs\tslibs\conversion.pxd", line 11, in init pandas._libs.tslib
File "pandas\_libs\tslibs\conversion.pyx", line 40, in init pandas._libs.tslibs.conversion
ModuleNotFoundError: No module named 'parsing'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/shaya/PycharmProjects/NEA/Main.py", line 4, in <module>
import pandas_datareader.data as data
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\base.py", line 7, in <module>
import pandas.compat as compat
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: No module named 'parsing' 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.
All of the above tracebacks are from PyCharm.
OS: Windows.
I am using pip to install packages
Python version: 3.7.1, panda version: 0.23.4
Do you have python added to path? To test this; open a cmd and type python. If it is on your path, you should see the version of python you are running (Assuming you are using a windows machine). If this is the case, you can simply run the command after you checked this. If not, please navigate to the location where Python is installed, open python.exe and try to run the command python setup.py build_ext --inplace --force
If this doesn't work, you should try to re-install pandas by pip install --upgrade --force-reinstall pandas
If this also fails you could also go rigourous, and simply create a new environment and install pandas there. Sidenote: It is probably better to install pandas by using conda package manager, Pandas has portions of its code written in C to make it run faster. If you tried to install pandas manually you would need to build it.
I had the same problem under the same circumstances. I went through the code of some of the pandas files and saw that there is indeed a module named 'parsing' in the tslib folder of my pandas directory, yet for some reason it's not able to call it. I just reinstalled python and now it's working for me. If you find any other alternative, please let me know.
I want to use regex package without installation (neither using pip nor python setup.py install)
For that, I have downloaded the package and kept in the same directory of the file where I am importing regex. The code is given below
import sys
import os
currentdirectory = os.getcwd()
sys.path.append(currentdirectory+"/packages/regex/Python2/")
from regex import *
I am getting following error as _regex extension module is not created.
Traceback (most recent call last):
File "test.py", line 30, in <module>
from regex import *
File "/Users/nilakshi/test_branch/packages/regex/Python2/regex.py", line 387, in <module>
import _regex_core
File "/Users/nilakshi/test_branch/packages/regex/Python2/_regex_core.py", line 21, in <module>
import _regex
ImportError: No module named _regex
How do I create _regex extension module that can be locally used?
Also, can I create _regex extension module file such that I can use the same file in different machines without creating again?
So, i have install the PIRT package for image registration. But i am not able to import it in my python. It is showing some error :
>>> import pirt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/osboxes/pirt/pirt/__init__.py", line 36, in <module>
from . import interp
File "/home/osboxes/pirt/pirt/interp/__init__.py", line 34, in <module>
from . import interpolation_
ImportError: No module named 'interpolation_'
when i take look to init.py file the line it show error on are import interp_ and import interpolation_. However these files are present in my current directory from where it is importing them.
osboxes#osboxes:~/pirt/pirt/interp$ ls
func.py __init__.py~ interpolation_.pxd interpolation_.pyx sliceinvolume.py
__init__.py interpolation_.c interpolation_.pxd~ __pycache__
now i don't understand why importing pirt from the python doesn't work. I am using python 3.5
Note :
it got solved by just building with
python setup.py build_ext --inplace
Webports has projects in the ports directory for Python and several Python modules, including NumPy. The "python" port compiles a Chrome app that runs the Python interpreter in a console window. I'd like to be able to use modules that include native code, like NumPy, in that interpreter.
Here's what I've tried:
make numpy followed by make python (in hopes that the Python build process sees that I've already built NumPy and includes it), which doesn't seem to change anything
Building the python-static package, which fails with a gigantic error message that ends with libppapi_simple_cpp.a: error: undefined reference to 'PSUserMainGet'
Copying out/build/numpy/numpy-1.8.0/numpy/ into the site-packages folder in pydata.tar in the Python app. import numpy fails with an error message telling me not to import NumPy from its source directory.
Copying out/build/numpy/numpy-1.8.0/build/lib.linux-x86_64-2.7/numpy/ (which appears to have compiled .so files in it) into the site-packages folder in pydata.tar. import numpy fails with this traceback:
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python2.7/site-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/lib/python2.7/site-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: cannot import name multiarray
I'm using the PNaCL toolchain version pepper_47 inside a Docker container to build the packages, and I'm running the Python app on Chrome 47.0.2526.106 (64-bit) on Xubuntu.
The raw python port doesn't catch it, but the numpy port was designed to be used with the python-static port, which will build using the modules that have previously been built. This will then assemble a unified static library that will be linked into the .pexe for python. You shouldn't need to copy any module components by hand.
I created my first package. When I try to install it with pip in a newly created virtualenv I get an error indicating that libs cannot be imported, yet they are added to the install_requires field in setup.py. If I do it outside a vierualenv, all is ok.
My setup.py is here: https://github.com/tdi/pyPEPA/blob/dev/setup.py
To reproduce the error:
mkvirtualenv something -p /usr/bin/python3
workon something
pip install pypepa
.
Downloading/unpacking pypepa
Running setup.py egg_info for package pypepa
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/tdi/.virtualenvs/koza/build/pypepa/setup.py", line 3, in <module>
import pypepa
File "./pypepa/__init__.py", line 6, in <module>
from pypepa.pepa_model import PEPAModel
File "./pypepa/pepa_model.py", line 6, in <module>
from pypepa.parsing.parser import PEPAParser
File "./pypepa/parsing/parser.py", line 5, in <module>
from pyparsing import Word, Literal, alphas, alphanums, nums, Combine, Optional, ZeroOrMore, Forward, restOfLine
ImportError: No module named 'pyparsing'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/home/tdi/.virtualenvs/koza/build/pypepa/setup.py", line 3, in <module>
import pypepa
File "./pypepa/__init__.py", line 6, in <module>
from pypepa.pepa_model import PEPAModel
File "./pypepa/pepa_model.py", line 6, in <module>
from pypepa.parsing.parser import PEPAParser
File "./pypepa/parsing/parser.py", line 5, in <module>
from pyparsing import Word, Literal, alphas, alphanums, nums, Combine, Optional, ZeroOrMore, Forward, restOfLine
ImportError: No module named 'pyparsing'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/tdi/.virtualenvs/koza/build/pypepa
Storing complete log in /home/tdi/.pip/pip.log
Your setup script imports pypepa which imports pypepa.pepa_model which imports pyparsing, but pyparsing is not installed yet (we haven’t even finished running the setup script to know what the dependencies are). The solution is to repeat the version number in pypepa and setup.py (so you can remove the import), or not import PEPAModel in __init__.py.
Python3 uses distutils and setup() will take a requires keyword arguments. From the docs:
Dependencies on other Python modules and packages can be specified by supplying the requires keyword argument to setup().
Change install_requires to requires in you setup.py script.