如何获得已安装的脚本以忽略PYTHONPATH [英] How do I get an installed script to ignore PYTHONPATH

查看:126
本文介绍了如何获得已安装的脚本以忽略PYTHONPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,如果我使用-E标志启动它,我可以让Python忽略PYTHONPATH.

I know I can get Python to ignore PYTHONPATH if I start it with the -E flag.

但是如何获得pip安装的脚本以具有此标志?

But how do I get a script installed by pip to have this flag?

我尝试了代码的脚本"和"console_scripts"部分,并且pip如果将它放在#上,则将-E剥离!线.

I tried both the "scripts" and the "console_scripts" section of the code and pip strips the -E if I put it on the #! line.

推荐答案

目前最简单的方法似乎是编写一个脚本,如果不包含该标志,它将重新启动Python:

The easiest way right now seems to be to put write a scripts that restarts Python if the flag is not included:

#!/bin/env python
import sys
if not sys.flags.ignore_environment:
      import os
      os.execv(sys.executable, [sys.executable, '-E'] + sys.argv)
# Run your actual script here

然后在setup.py中,输入以下内容:

Then in setup.py, put this:

setup(..., scripts=['myscript'], ...)

请勿使用entry_points/console_scripts.不应将其用于公共模块,而仅用于内部脚本.

Don't use entry_points/console_scripts. This should not be used for public modules, just for internal scripts.

这篇关于如何获得已安装的脚本以忽略PYTHONPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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