Import Pythom modules between directories at the same level - python

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

Related

ValueError and ImportError inside package directory when import variable from init file

I have a directory application in which I have two files. init.py and routes.py. I have set a variable in init.py. while I am one directory below package directory application , I am able to import the variable.
>>> from application import hello_api_blueprint
>>> hello_api_blueprint
<flask.blueprints.Blueprint object at 0x7f4d6869da10>
But when I am inside package directory - application I am not able to import with multiple way
>>> from application import hello_api_blueprint
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named application
>>> from . import hello_api_blueprint
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
How can I import this variable when I am inside the directory.

How can I solve this cannot ImportError: cannot import name in python3

Repository for reference --> https://github.com/SavSanta/bluinfo
So, Im trying to import a class BDROM I made in the file called bluinfo.py. (line 27)
By adding the line from bluinfo import BDROM to the bluinfo-gui.py (line 8)
I am receiving ImportError: cannot import name 'BDROM'
I can not figure out how to get this badboy to work. Other posts state it may be related to PYTHONPATH (despite similar imports have been working in other parts of the program and all files are in the same directory).
I've tried to alter the import statement in the following ways to no success:
from .bluinfo import BDROM
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '__main__.bluinfo'; '__main__' is not a package
from ..bluinfo import BDROM
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: attempted relative import beyond top-level package
Creating an init.py file (which I believe I read is unnecessary in python3.x) and trying the import
$dev:/tmp/blue/bluinfo$ touch __init__.py
$dev:/tmp/blue/bluinfo$ python3 bluinfo-gui.py
Traceback (most recent call last):
File "bluinfo-gui.py", line 8, in <module>
from bluinfo import BDROM
File "/tmp/blue/bluinfo/bluinfo.py", line 8, in <module>
import ts_scanner as ScanTask
File "/tmp/blue/bluinfo/ts_scanner.py", line 5, in <module>
import ts_streamtypeclass
File "/tmp/blue/bluinfo/ts_streamtypeclass.py", line 3, in <module>
from bluinfo import BDROM
ImportError: cannot import name 'BDROM'
Any ideas appreciated!
In your third attempt you have a circular import. Restructure your code to avoid that.
For example, you might be able to eliminate one of these imports, and you will get rid of the circular dependency.
File "/tmp/blue/bluinfo/bluinfo.py", line 8, in <module>
import ts_scanner as ScanTask
File "/tmp/blue/bluinfo/ts_streamtypeclass.py", line 3, in <module>
from bluinfo import BDROM
PS: Since you have a file called blueinfo.py in a directory called blueinfo, the statement import blueinfo might mean either the package (directory) or the module (file). You could consider renaming the files inside the blueinfo directory to something more descriptive, to avoid this ambiguity.

library importing issues in pycharm

I'm doing a project on opencv python which is based on downloaded source code from the internet. When I run the code, this error occurs
C:\Users\Udara\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/Udara/Desktop/7777/people-counting-opencv/people_counter.py
Traceback (most recent call last):
File "C:/Users/Udara/Desktop/7777/people-counting-opencv/people_counter.py", line 13, in <module>
from pyimagesearch.centroidtracker import CentroidTracker
File "C:\Users\Udara\Desktop\7777\people-counting-opencv\pyimagesearch\centroidtracker.py", line 5, in <module>
import ordereddict
File "C:\Users\Udara\AppData\Local\Programs\Python\Python38-32\lib\site-packages\ordereddict.py", line 23, in <module>
from UserDict import DictMixin
ModuleNotFoundError: No module named 'UserDict'

Importing quandl using python 27

I'm trying to import quandl and have downloaded it from Github and unzipped it to C:\Python27\Lib\site-packages\quandl but whenever I run my file "quandltest.py", I get "ImportError: No module named inflection". I then downloaded inflection from Github and saved it to the site-packages folder but still get the following whenever I run the file. I'm using a Python 27 IDLE to import quandl (I get the same error using Pycharm). Anyone have any idea/the same issue?? Thanks! I also do not have access to my command window as it has been disabled by the admin so I cannot pip install.
Traceback (most recent call last):
File "C:/Python27/quandltest.py", line 1, in <module>
import quandl
File "C:\Python27\lib\site-packages\quandl\__init__.py", line 7, in <module>
from .model.database import Database
File "C:\Python27\lib\site-packages\quandl\model\database.py", line 11, in <module>
from quandl.connection import Connection
File "C:\Python27\lib\site-packages\quandl\connection.py", line 5, in <module>
from .util import Util
File "C:\Python27\lib\site-packages\quandl\util.py", line 1, in <module>
from inflection import parameterize
ImportError: No module named inflection

Error in importing PIRT( Python Image Registration Toolkit) in python

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

Categories

Resources