简体   繁体   English

在mac osx中设置python路径?

[英]Set up python path in mac osx?

I installed python on mac os (mountain lion) with Macports. 我用Macports在mac os(山狮)上安装了python。 When I run $python It gives an error on "cannot import urandom" when I try to import pandas or matplotlib. 当我运行$ python当我尝试导入pandas或matplotlib时,它在“无法导入urandom”时出错。

If I run $python 2.7 Everything runs perfectly. 如果我运行$ python 2.7一切运行完美。

I want to change python to use python2.7 always. 我想改变python总是使用python2.7。

I tried using sudo port select python python27. 我尝试使用sudo port select python python27。 But that didn't help. 但这没有帮助。

Please help me on this, I'm new to mac. 请帮助我,我是mac的新手。

First let me preface by saying that OSX already comes with python installed. 首先让我先说一下OSX已经安装了python。 Lion and Mountain Lion have python2.7 as the system defaults. Lion和Mountain Lion有python2.7作为系统默认值。

Now assuming you really did want to use a macports version, my guess is that you only installed it, but didn't do the step of modifying your PATH to have it look first for macport installed executables... 现在假设您确实想要使用macports版本,我的猜测是您只安装了它,但是没有修改PATH的步骤让它首先看看macport安装的可执行文件...

Installing MacPorts 安装MacPorts

  1. Edit your ~/.profile 编辑你的~/.profile
  2. Add this line: export PATH=/opt/local/bin:/opt/local/sbin:$PATH 添加以下行: export PATH=/opt/local/bin:/opt/local/sbin:$PATH

The next time you open a shell, it will place the macports install location at the front of your path, giving you access to the executables. 下次打开shell时,它会将macports安装位置放在路径的前面,使您可以访问可执行文件。

If I remember correctly, you may want to do a "sudo port activate python" . 如果我没记错的话,你可能想做一个"sudo port activate python" What does "which python" tell you? "which python"告诉你什么? If it's /usr/bin/python , you're running OSX Python. 如果它是/usr/bin/python ,那么你正在运行OSX Python。 If, OTOH, it's /usr/local/bin/python you're probably using the ports version. 如果,OTOH,它是/usr/local/bin/python你可能正在使用ports版本。

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

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