如何将PYTHONPATH重置为“默认”在virtualenv中的值? [英] How do I reset PYTHONPATH to "default" value in virtualenv?

查看:438
本文介绍了如何将PYTHONPATH重置为“默认”在virtualenv中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我读到我应该检查安装路径是否在我的PYTHONPATH中时,我正在努力为外部库安装依赖关系(要求已经实现)。没有,所以我查了如何添加。

I was struggling with installing dependencies for an external library (the requirements were already fulfilled) when I read that I should check if the install path is in my PYTHONPATH. It wasn't, so I looked up how to add it.

我遇到这个答案,并将代码直接输入终端(不是〜/ .bashrc )。

I came across this answer, and typed the code straight into the Terminal (not ~/.bashrc) before I finished reading.


如果您使用bash(在Mac上)或GNU / Linux发行版),将其添加到〜/ .bashrc

If you're using bash (on a Mac or GNU/Linux distro), add this to your ~/.bashrc

export PYTHONPATH =$ {PYTHONPATH}:/ my / other /路径

我输入的路径是 / usr / bin / python

令人惊讶的是,这固定了所有的依赖问题。

Surprisingly this fixed all of my dependency problems.

然而,由于我的Django项目依赖于virtualenv,所以这毁了一切。我不能再找到如何还是在哪里恢复我的PYTHONPATH。

However, since my Django project is dependent on a virtualenv, this ruined everything. I can no longer find how or where to restore my PYTHONPATH to.

我尝试过 export PYTHONPATH =/ home / [username] /。virtualenvs / [env] / bin / python并且还使用 rmvirtualenv 删除virtualenv。

I tried export PYTHONPATH="/home/[username]/.virtualenvs/[env]/bin/python" and also deleting the virtualenv with rmvirtualenv.

我的下一个计划是删除项目并再次拉。

My next plan is to delete the project and pull again.

推荐答案

在Django 设置模块的顶部,您可以包括

At the top of your Django settings module, you could include:

import sys
sys.path.append('/your/dependency/path')

这篇关于如何将PYTHONPATH重置为“默认”在virtualenv中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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