问题描述
当我读到我应该检查安装路径是否在我的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.
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中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!