Python:引用另一个项目 [英] Python: Referencing another project

查看:794
本文介绍了Python:引用另一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从命令行运行我的Python项目。我引用其他项目,所以我需要能够在其他文件夹中运行模块。

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

这个工作的一个方法是修改Pythonpath环境变量,但我认为这是一个滥用。另一个黑客将复制所有我想要的文件到一个单一的目录,然后运行Python。有更好的方法吗?

One method of making this work would be to modify the Pythonpath environment variable, but I think this is an abuse. Another hack would be to copy all the files I want into a single directory and then run Python. Is there a better method of doing this?

注意:我实际上是在Eclipse编程,但我想能够远程运行程序。

Note: I am actually programming in Eclipse, but I want to be able to run the program remotely.

类似问题:

  • Referencing another project: This question is basically asking how to import

推荐答案

如果您导入sys,它包含PYTHONPATH中的目录列表为sys.path

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

list(sys.path.append(my / path))允许您从当前模块中的那些位置正常导入,而不改变系统上的全局设置。

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

这篇关于Python:引用另一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆