I'm in the process of redesigning/refactoring my Python quantum chemistry package (pyquante). One of the things I don't like about the existing release is that I have to install the package to run the test suite. That is, the test suite has statements like from PyQuante import SCF
, and, of course, this PyQuante could refer to the installed version or a local version.
我正在重新设计/重构我的Python量子化学包(pyquante)。我不喜欢现有版本的一个地方是,我必须安装包来运行测试套件。也就是说,测试套件具有类似于PyQuante导入SCF的语句,当然,这个PyQuante可以引用已安装的版本或本地版本。
I know about virtualenv, and realize this is an option for me. But I was wondering whether anything else might be appropriate. In the past I've hacked sys.path
for things like this, and have been told by better Python programmers that I shouldn't ever to this.
我了解virtualenv,并意识到这是我的选择。但我想知道是否还有其他合适的。过去我曾入侵过sys。这类事情的路径,更好的Python程序员告诉我,我不应该这样做。
Does anyone have any suggestions for how I can do this? The point is that I want to test the current version of the code without installing it.
有人对我怎么做有什么建议吗?关键是,我想在不安装代码的情况下测试代码的当前版本。
Thanks in advance for anyone who can see through my babbling and offer suggestions!
感谢所有能看穿我的胡言乱语并提供建议的人!
3 个解决方案
#1
17
Create a proper package for your stuff and use
为你的东西和使用创建一个合适的包
python setup.py develop
to make it a proper dev-package.
让它成为一个合适的deva包。
See:
看到的:
- https://*.com/a/19048754/548039
- https://*.com/a/19048754/548039
- http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
- http://setuptools.readthedocs.io/en/latest/setuptools.html开发模式
#2
4
I would honestly insist on using virtualenv, its designed for this exact reason in mind. very small overhead, and if you ever mess up just delete directory. I am sure as you grow, things won't be as simple as they are now for your current situation. Take it as an opportunity to learn.
我真诚地坚持使用virtualenv,它的设计就是为了这个确切的原因。非常小的开销,如果您搞砸了,请删除目录。我相信随着你的成长,事情不会像现在这样简单。把它当作一个学习的机会。
#3
2
Altering sys.path
much in production environment may be unwise. Altering it for testing is usually OK.
改变系统。生产环境中的许多路径可能是不明智的。为了测试而改变它通常是可以的。
If you don't want to tinker with the variable from sys
, use an environment variable named PYTHONPATH
, it's a clean and documented way.
如果您不想修改来自sys的变量,请使用一个名为PYTHONPATH的环境变量,这是一种干净的、有文档记录的方法。
#1
17
Create a proper package for your stuff and use
为你的东西和使用创建一个合适的包
python setup.py develop
to make it a proper dev-package.
让它成为一个合适的deva包。
See:
看到的:
- https://*.com/a/19048754/548039
- https://*.com/a/19048754/548039
- http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode
- http://setuptools.readthedocs.io/en/latest/setuptools.html开发模式
#2
4
I would honestly insist on using virtualenv, its designed for this exact reason in mind. very small overhead, and if you ever mess up just delete directory. I am sure as you grow, things won't be as simple as they are now for your current situation. Take it as an opportunity to learn.
我真诚地坚持使用virtualenv,它的设计就是为了这个确切的原因。非常小的开销,如果您搞砸了,请删除目录。我相信随着你的成长,事情不会像现在这样简单。把它当作一个学习的机会。
#3
2
Altering sys.path
much in production environment may be unwise. Altering it for testing is usually OK.
改变系统。生产环境中的许多路径可能是不明智的。为了测试而改变它通常是可以的。
If you don't want to tinker with the variable from sys
, use an environment variable named PYTHONPATH
, it's a clean and documented way.
如果您不想修改来自sys的变量,请使用一个名为PYTHONPATH的环境变量,这是一种干净的、有文档记录的方法。