Python Forum
[SYS + OS] Script not Imported, Error Found !
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[SYS + OS] Script not Imported, Error Found !
#1
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.
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  file open "file not found error" shanoger 8 938 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Module Not Found Error bitoded 4 1,343 Jan-01-2023, 09:08 AM
Last Post: bitoded
  File not found error saisankalpj 10 3,697 Jul-04-2022, 07:57 AM
Last Post: saisankalpj
  Can a module tell where it is being imported from? stevendaprano 3 1,140 Apr-12-2022, 12:46 AM
Last Post: stevendaprano
  module detecting if imported vs not Skaperen 1 1,637 Nov-19-2021, 07:43 AM
Last Post: Yoriz
  TypeError: sequence item 0: expected str instance, float found Error Query eddywinch82 1 5,023 Sep-04-2021, 09:16 PM
Last Post: eddywinch82
  Error when refering to class defined in 'main' in an imported module HeRo 2 2,330 Apr-13-2021, 07:22 PM
Last Post: HeRo
  [newbie] Why is a module imported twice? Winfried 3 4,033 Apr-02-2021, 04:48 AM
Last Post: deanhystad
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,500 Nov-23-2020, 05:15 PM
Last Post: cananb
  Unknown error occurred: Port not found NewBeie 0 1,406 Aug-27-2020, 08:50 PM
Last Post: NewBeie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020