作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的.bash_profile
PYTHONPATH=".:/home/miki725/django/django:$PYTHONPATH"
export PYTHONPATH
然后我打开 python,但是我在 .bash_profile
中添加的目录不是第一个:
Python 2.4.3 (#1, Sep 21 2011, 20:06:00)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for i in sys.path:
... print i
...
/usr/lib/python2.4/site-packages/setuptools-0.6c9-py2.4.egg
/usr/lib/python2.4/site-packages/flup-1.0.2-py2.4.egg
/usr/lib/python2.4/site-packages/MySQL_python-1.2.3c1-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/django_form_utils-0.1.7-py2.4.egg
/usr/lib/python2.4/site-packages/mechanize-0.2.1-py2.4.egg
/usr/lib/python2.4/site-packages/Django-1.2.1-py2.4.egg
/usr/lib/python2.4/site-packages/mercurial-1.6-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/lxml-2.2.7-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/django_registration-0.7-py2.4.egg
/usr/lib/python2.4/site-packages/sorl_thumbnail-3.2.5-py2.4.egg
/usr/lib/python2.4/site-packages/South-0.7.2-py2.4.egg
/usr/lib/python2.4/site-packages/django_keyedcache-1.4_1-py2.4.egg
/usr/lib/python2.4/site-packages/django_livesettings-1.4_3-py2.4.egg
/usr/lib/python2.4/site-packages/django_app_plugins-0.1.1-py2.4.egg
/usr/lib/python2.4/site-packages/django_signals_ahoy-0.1_2-py2.4.egg
/usr/lib/python2.4/site-packages/pycrypto-2.3-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/django_threaded_multihost-1.4_0-py2.4.egg
/usr/lib/python2.4/site-packages/PIL-1.1.7-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/pyOpenSSL-0.11-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/ZSI-2.0_rc3-py2.4.egg
/usr/lib/python2.4/site-packages/PyXML-0.8.4-py2.4-linux-i686.egg
/usr/lib/python2.4/site-packages/pyquery-0.6.1-py2.4.egg
/usr/lib/python2.4/site-packages/pip-1.0.1-py2.4.egg
/usr/lib/python2.4/site-packages/virtualenv-1.6.1-py2.4.egg
/usr/lib/python2.4/site-packages/simplejson-2.1.6-py2.4-linux-i686.egg
/home/miki725
/home/miki725/django/django
/usr/lib/python24.zip
/usr/lib/python2.4
/usr/lib/python2.4/plat-linux2
/usr/lib/python2.4/lib-tk
/usr/lib/python2.4/lib-dynload
/usr/lib/python2.4/site-packages
/usr/lib/python2.4/site-packages/Numeric
/usr/lib/python2.4/site-packages/PIL
/usr/lib/python2.4/site-packages/gtk-2.0
>>>
>>>
>>>
>>>
>>> import django
>>> django.__file__
'/usr/lib/python2.4/site-packages/Django-1.2.1-py2.4.egg/django/__init__.pyc'
>>>
如何添加到 .bash_profile
中的 python 路径,以便它位于开头。这是用于共享托管。我需要能够导入我的 django 安装而不是使用系统默认值。
谢谢
最佳答案
最好的办法是在运行时修改sys.path
。在共享托管环境中,通常在 .wsgi 文件中执行此操作。你可以这样做:
import sys
sys.path.insert(0, '/home/miki725/django/django')
如果您将 export PYTHONSTARTUP=/home/miki725/.pythonrc
添加到 .bash_profile
中,则可以添加您的 .pythonrc
文件,并且它也会在显示交互式提示之前执行。
关于python - 如何在 bash 中添加到起始 Python 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8337686/
我是一名优秀的程序员,十分优秀!