I wanted to import basic functions in the python shell included in paraview. I tried:
import os
os.chdir('/path/to/my/directory')
import hello_world
Got the result:
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'hello_world' is not defined
while I have a hello_world.py in the directory …
Try this instead:
import sys
sys.path.append("/path/to/my/directory")
import hello_world
Related
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
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
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?
when I run the command to import my python file, i am getting import error saying no modue named app.management.commands.
>>> from app.management.commands import scripty
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named app.management.commands
Can anyone please help me.
Is app.management.commands in your sys path?
Looks like you have to import it using <project_name>.app.management.commands.
When I try to import multiprocessing in Python 2.7.5 on OS X 10.6.8, I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/__init__.py", line 65, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/multiprocessing/util.py", line 40, in <module>
from subprocess import _args_from_interpreter_flags
ImportError: cannot import name _args_from_interpreter_flags
I also tried to install python2.7.6 with homebrew, but this error still occurs.
It sounds like a circular import issue. Try adding this to the the rest of your imports:
from subprocess import _args_from_interpreter_flags
There is a comment above the function in subprocess.py:
# XXX This function is only used by multiprocessing and the test suite,
# but it's here so that it can be imported when Python is compiled without
# threads.
May be related.