Python: link to another project

I want to be able to run a Python project from the command line. I refer to other projects, so I need to be able to run modules in other folders.

One way to do this work is to change the Pythonpath environment variable, but I believe this is an abuse. Another hack is to copy all the files that I want into one directory, and then run Python. Is there a better way to do this?

Note. I really program in Eclipse, but I want to be able to run the program remotely.

Related questions:

+4
source share
5 answers

If you import sys, it contains a list of directories in PYTHONPATH as sys.path

Adding directories to this list (sys.path.append ("my / path")) allows you to import from these places in the current module as usual, without changing the global settings on your system.

+10
source

Take a look at tools like

+5
source

Firstly, I am sure that the module I want to enable has not been installed globally. Then I add a symlink to the includee directory:

# With pwd == module to which I want to add functionality. ln -s /path/to/some_other_module_to_include . 

and then I can do standard import. This allows you to use multiple versions, etc. This does not require changing any global settings, and you do not need to change the program code if you are working on different machines (just change the symbolic link).

+1
source

If "run modules" you mean importing them, you might be interested in this question, which I asked some time ago.

0
source

I just realized that I really solved this problem before. Here is the approach I used - much more complicated than mavnn, but I also solved the problem of running the Python2.x program from Python 3.0

 import os import subprocess env=os.environ.copy() env['PYTHONPATH']=my_libraries kwargs={"stdin":subprocess.PIPE, "env":env} subprocess.Popen(["python","-u",program_path],**kwargs) 
0
source

All Articles