0

How do you specify a certain path for the import thing to import?

such as import "E:\Tom's Personal Project\engine\shared.py" Any help would be appreciated :)

3
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by vegaseat
0

Refer here for details on how to make a "Package" taking advantage of __init__.py files... should get you going

0

i tried what it said on the site but it didn't work
error:
Traceback (most recent call last):
File "E:/Tom's Personal Project/engine/world/worldloader.py", line 6, in <module>
import shared.print.newPrint
ImportError: No module named shared.print.newPrint

folders:

Tom's Personal Project   
    engine
        world
            WorldLoader.py
            WorldLoader.ini
        shared
            __init__.py
            print
                __init__.py
                newPrint.py

my code:

import shared.print.newPrint

Any help would be apprecieted :)

0

Where are you running your script from? Try os.getcwd() at the beginning of your script to make sure you're actually in the TPP/engine directory.

1

i am running the worldloader.py file

Try os.getcwd() at the beginning of your script to make sure you're actually in the TPP/engine directory.

Unless you're actually running the script from within the TPP/engine directory you'll need to add it to your path. You can do that at the beginning of your script like so:

import sys

sys.path.append('/home/TPP/engine')
# Rest of your code....
Votes + Comments
thanks for a good solution
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.