How can I import functions from other folders in Python project? - python

I cannot import the functions from other packages in my Python project.
As suggested, I added
sys.path.append(os.path.abspath('../ExportExcel'))
from ExportExcel.export_excel import export_excel
at the beginning of the clip_finder.py.
I also put
sys.path.append(os.path.dirname(__file__)
inside the export_excel.py.
Inside ExportExcel.init.py I put
from .export_excel import export_excel
However I still get this error:
C:\Main\SupportScripts\ClipFinder>python clip_finder.py -h
Traceback (most recent call last):
File "C:\Main\SupportScripts\ClipFinder\clip_finder.py", line 12, in <module>
from ExportExcel.export_excel import export_excel
ModuleNotFoundError: No module named 'ExportExcel'
How can I make it work?

Related

Importing modules in embedded python

I'm trying to get module imports to work in embeddable python, but it doesn't want to work
C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32>type run_scripts\script.py
from module_test import test
print("Hello world!")
print(test())
C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32>type run_scripts\module_test.py
def test():
return "Test!"
C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32>#python.exe run_scripts\script.py
Traceback (most recent call last):
File "C:\Users\test\Desktop\winpy\python-3.10.10-embed-win32\run_scripts\script.py", line 1, in <module>
from module_test import test
ModuleNotFoundError: No module named 'module_test'
Why is the module not being imported? I tried changing PYTHONPATH but it didn't help

import from utils import module returns cannot import even though other modules from same file work

I have a utils file from a GitHub repo and I added some simple functions to it (to unpick and pickle) and the import statement
from utils import existing_module, unpicklefile
returns the following
Traceback (most recent call last):
File "<input>", line 1, in <module>
ImportError: cannot import name 'unpicklefile' from 'utils'
but the other functions import fine, so this isn't a sys.path error.
Help :D

Unable to import RocksDB module

I am fairly new to working with RocksDB. I have set up the environment for RocksDB following the link here, but when I run a sample Python script having import rocksdb it says:
Traceback (most recent call last):
File "`<string>`", line 1, in <module>
ModuleNotFoundError: No module named 'rocksdb'
Can anybody suggest a solution to this issue?

Error while importing localization

I downloaded the localization package in Anaconda. But when I try to import it I get the following error:
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import localization File "~\Python\Python36-32\lib\site-packages\localization\__init__.py", line 1, in <module>
from geoProject import *
ModuleNotFoundError: No module named 'geoProject'
I do not know what to do, can someone please help me out?
"geoProject", must be your project name, not the name of the module you are trying to input.
Try:
from your module import *
or just
import yourmodule
It works if your module is in current directory. Unless you should write the full path to your module

How to add python library to Spyder

I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:
Adding library path containing .py files to Tools>PYTHONPATH manager
Synchronizing the path
Updating module names list through Tools>Update Module names list
However, when I try to import modules from this library I get two types of errors:
import easy
Traceback (most recent call last):
File "<ipython-input-2-685519d35f15>", line 1, in <module>
import easy
File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
from .server import Server, InputProcessor
ValueError: Attempted relative import in non-package
The second type of error as follows:
from plxscripting.easy import *
Traceback (most recent call last):
File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
from plxscripting.easy import *
ImportError: No module named plxscripting.easy
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?

Categories