Python Forum

Full Version: [SYS + OS] Script not Imported, Error Found !
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey Python Programmers...

I Try to train my self in working with SYS and OS. In this case... create an simple
program they get more python scripts loading. But now... this is an simple test.

My first script you must start with:
import os
import sys
import jamics

module = "../script/module/jamics"

script = sys.path.append(os.path.abspath(module))

print("Script Map: ", script)
This give the bigest problem. This script must be load my other module script jamics,
but it doesn't. I get just an error. Python said thad jamics is not cognized.


So... this is my other script for my test with os and sys.

My seccond script they must be importing from my first script:
print("Jamics Imported !...")
Can anyone see whats wrong with my script ?... i don't can see the problem.
They are two test scripts to test my knowledge for import files with os and sys.
This is an simple test.

Can anyone help me to tell what the problem is ?...

Thanks, Jamie.
You need to do the import after changing sys.path. Also, you should be able to set your system to check that folder automatically by setting the PYTHONPATH environment variable. How you do that depends on your operating system. Using PYTHONPATH is the preferred method.
If scripts are in same folder or in jamics.py in PYTHONPATH.
C:\foo\
  |-- jamics.py
  |-- run.py
# jamics.py
def jam():
    return ("Jamics Imported !...")
# run.py
import jamics

# using module jamics
print(jamics.jam())
Test:
Output:
C:\foo λ python run.py Jamics Imported !..
Placing jamics.py in a place Python do not search(sys.path).
import sys
# Before import jamics
sys.path.append('C:/somefolder/anotherfolder')
import jamics

# using module jamics
print(jamics.jam())