简体   繁体   English

在 OS X 中设置 pythonpath

[英]Setting up pythonpath in OS X

A new PHP developer here trying to learn Python/Django using the "Tango With Django" tutorial.一位新的 PHP 开发人员正在尝试使用“Tango With Django”教程来学习 Python/Django。

I'm up to section 2.2.2 where I have to set up the pythonpath and I'm having the following problem:我在第 2.2.2 节中必须设置 pythonpath,但遇到以下问题:

When I type the following in the terminal: echo $pythonpath I get a blank line instead of the correct path.当我在终端中输入以下内容时: echo $pythonpath我得到一个空行而不是正确的路径。

I followed the troubleshooting steps and found where the site-packages directory is: Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages我按照故障排除步骤找到了 site-packages 目录的位置: Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Per their instructions I updated my .bashrc file so it looks like this now:根据他们的指示,我更新了我的.bashrc文件,现在看起来像这样:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PYTHONPATH=$PYTHONPATH:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

For a reason I don't understand I'm still getting a blank line when I echo $pythonpath .出于某种原因,我不明白我在echo $pythonpath时仍然得到一个空行。

Because I was having difficulty getting the pythonpath set up I skipped it, but then had problems installing Setuptools, Pip, and Django.因为我在设置pythonpath时遇到了困难,所以我跳过了它,但是在安装 Setuptools、Pip 和 Django 时遇到了问题。

Can anyone tell me what I'm doing wrong?谁能告诉我我做错了什么? Any resources I can look at beside Tango with Django?除了 Tango with Django,我还可以查看哪些资源?

2 issues I can see -我能看到的 2 个问题 -

  1. $pythonpath and $PYTHONPATH are different. $pythonpath 和 $PYTHONPATH 是不同的。 You want $PYTHONPATH.你想要 $PYTHONPATH。 You will never use the lower-case version $pythonpath for anything, everything Python will 'respond' to will be in uppercase (by default)您永远不会将小写版本的 $pythonpath 用于任何事情,Python 将“响应”的所有内容都将是大写的(默认情况下)

  2. By default, $PYTHONPATH is empty and only necessary to add additional paths to beyond the defaults.默认情况下, $PYTHONPATH 是空的,只需要在默认值之外添加额外的路径。 To see the default list you can run this command in a shell:要查看默认列表,您可以在 shell 中运行此命令:

     python -c 'import sys;print sys.path'

More than likely, the path you want will be in that list.您想要的路径很可能在该列表中。

For a reason I don't understand I'm still getting a blank line when I echo $pythonpath.出于某种原因,我不明白我在回显 $pythonpath 时仍然得到一个空行。

Environment variables are case sensitive.环境变量区分大小写。 PYTHONPATH and pythonpath are different. PYTHONPATHpythonpath是不同的。 So:所以:

echo $PYTHONPATH

First you should make sure that .bashrc is being executed when you open a new terminal screen.首先,您应该确保在打开新终端屏幕时正在执行 .bashrc。

If it doesn't, i recommend adding the following line to .bash_profile under your user home directory: [[ -s ~/.bashrc ]] && source ~/.bashrc如果没有,我建议将以下行添加到您的用户主目录下的 .bash_profile: [[ -s ~/.bashrc ]] && source ~/.bashrc

this line will make sure .bashrc exist, and if it does, it will execute it.这一行将确保 .bashrc 存在,如果存在,它将执行它。 As mentioned, both .bash_profile and .bashrc should be located under /Users//如前所述,.bash_profile 和 .bashrc 都应该位于 /Users// 下

Hope this helps.希望这可以帮助。 Meny梅尼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM