如何在 virtualenv 中添加到 PYTHONPATH 的路径 [英] How do I add a path to PYTHONPATH in virtualenv

查看:46
本文介绍了如何在 virtualenv 中添加到 PYTHONPATH 的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 PYTHONPATH 环境变量添加路径,该路径仅在特定的 virtualenv 环境中可见.

I am trying to add a path to the PYTHONPATH environment variable, that would be only visible from a particular virtualenv environment.

我在 virtualenv 命令提示符下尝试了 SET PYTHONPATH=...,但这为整个环境设置了变量.

I tried SET PYTHONPATH=... under a virtualenv command prompt, but that sets the variable for the whole environment.

我如何做到这一点?

推荐答案

你通常可以通过 使用 .pth 文件.只需在您的 virtualenv 的 site-packages 文件夹中放置一个扩展名为 .pth 的文件(任何基本名称都有效),例如lib\python2.7\site-packages,以包含包的目录的绝对路径作为其唯一内容.

You can usually avoid having to do anything with PYTHONPATH by using .pth files. Just put a file with a .pth extension (any basename works) in your virtualenv's site-packages folder, e.g. lib\python2.7\site-packages, with the absolute path to the directory containing your package as its only contents.

这篇关于如何在 virtualenv 中添加到 PYTHONPATH 的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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