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
Related
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.
My project structure:
Now In XMLHelper.py file under the Utility package i have the below import:
from ..Common import BaseScreen
From Pycharm I right click the ResultSettingScreen.py to run the script.
I get error below
/usr/bin/python3.8 xxxx/src/FiveInch/800x480/ResultSettingScreen.py
Traceback (most recent call last):
File "xxxx/src/FiveInch/800x480/ResultSettingScreen.py", line 22, in <module>
from Utility import XMLHelper
File "xxxx/src/FiveInch/800x480/Utility/XMLHelper.py", line 5, in <module>
from ..Common import BaseScreen
ValueError: attempted relative import beyond top-level package
When I run a script in Anaconda Prompt, it works fine.
When I try to run it via PyCharm, I get this error related to the import of pandas.
C:\ProgramData\Anaconda3\python.exe C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py
Traceback (most recent call last):
File "C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py", line 2, in <module>
import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Process finished with exit code 1
If I try to import numpy and run it via PyCharm I get:
C:\ProgramData\Anaconda3\python.exe C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py", line 2, in <module>
import numpy as np
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
Process finished with exit code 1
Running the same script in Anaconda prompt...no problem
My run configuration in PyCharm uses the Anaconda python distribution?
It should be noted that I am not using envirnoments, just the base Anaconda installation. More worryingly I dont see ANY Conda options in the project settings in PyCharm which a lot of tutorials seem to allude to.
Seems like a problem with the path for your scripts. Are you sure You have included your scripts in the PATH variable? If so are you sure your libraries are downloading/installing in that path?
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?
I'm using Anaconda3 version 4.2.0 on ubuntu (in docker).
Anaconda is installed in /root/anaconda3 folder.
I installed theano_bpr package using pip install theano_bpr.
Now when i open python and try import theano_bpr, i get the following message:
>>> import theano_bpr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/anaconda3/lib/python3.5/site-packages/theano_bpr/__init__.py", line 17, in <module>
from bpr import BPR
ImportError: No module named 'bpr'
However, when i navigate to /root/anaconda3/lib/python3.5/site-packages/theano_bpr/ and run python there, i'm able to import theano_bpr.
In /root/anaconda3/lib/python3.5/site-packages/theano_bpr/ there are following files:
__init__.py, bpr.py (this one is causing problems), t.py, and utils.py.