file location/directory

Gys invalid at invalid.com
Tue Mar 16 09:02:33 EDT 2021


On 3/14/21 7:44 PM, Quentin Bock wrote:
> how can I change the path that python takes to run certain files, I'm
> starting to create game and I want those in separate folders, so how can I
> change it so that python runs the program with the files from that folder?
> 
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
> Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

Hi Quentin Bock,
this is a very dense subject. The simplest sulution is to create a 
MainFolder with the main module of your game. Then in that folder, 
create a SubFolder where you can store the modules your game wants to 
import.

The alternative is to use the Environment variable $PYTHONPATH

<https://scipher.wordpress.com/2010/05/10/setting-your-pythonpath-environment-variable-linuxunixosx/>

Setting Your PYTHONPATH environment variable (Linux/Unix/OsX)

Open your personal .bashrc file at /home/<YourName>/.bashrc
Note that this is a hidden file
Add these 2 lines :

PYTHONPATH="${PYTHONPATH}:/path/cool/python/package/"
export PYTHONPATH

These checks the settings :

import os
import sys
print(sys.path)
print(os.environ.get('PYTHONPATH', ''))

-hth
Gys


More information about the Python-list mailing list