Mac OS X的/斌/ bash中:蟒蛇:命令在某些IDE未找到 [英] Mac OS X /bin/bash: python: command not found in some IDE

查看:319
本文介绍了Mac OS X的/斌/ bash中:蟒蛇:命令在某些IDE未找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译 test.py 在崇高的文本或codeRunner(一个非常简单的Python文件),我得到了错误: /斌/ bash中:蟒蛇:命令未找到。接着我输入蟒蛇test.py 在终端的应用程序,它的工作。后来我下载Pycharm并重新编译的文件,它的工作呢!

When I compiled test.py(a very simple Python file) in Sublime Text or CodeRunner, I got the error:/bin/bash: python: command not found. Then I input python test.py in the Terminal app, it worked. Later I downloaded Pycharm and compiled the file again, it worked too!

所以我假设有某种路径设置或别的东西,这不是正确设置。我搜索过相当长的时间上网,但没有用的。请帮忙还是尽量给一些想法如何解决这个问题。

So I assume there is some kind of path setting or something else that was not set correctly. I've searched for quite a long time on the internet but no use. Please help or try to give some ideas how to solve the problem.

下面是一些细节:


  1. 我试着插入#!在/ usr /斌/ Python的 test.py 文件的顶部,但没有用

  1. I've tried inserting #! /usr/bin/python at the top of test.py file but no use

回声$ PATH在码头的输出<$c$c>/usr/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Users/chenyang/Downloads/android-sdk-macosx/platform-tools

我发现的Python的几个版本中我的MacBook:2.6,2.7,3.2,3.3,3.5。在文件夹 /System/Library/Frameworks/Python.framework/Versions 我发现2.6,2.7。在文件夹 /Library/Frameworks/Python.framework/Versions 我发现3.2,3.3,3.5。

I've found several versions of Python in my macbook :2.6, 2.7, 3.2, 3.3, 3.5. Under the folder /System/Library/Frameworks/Python.framework/Versions I found 2.6, 2.7. Under the folder /Library/Frameworks/Python.framework/Versions I found 3.2, 3,3, 3.5.

我已经解决了自己的问题,并张贴下面的答案

推荐答案

终端加载大量的文件,可以修改PATH变量,包括〜/ .profile文件〜/ .bashrc中〜/ .bash_profile中等,这些没有得到加载时,Mac OS X系统UI启动/当你通过Finder中的应用程序登录到您的用户配置文件。因此,应用通过搜索开始不继承PATH和在这些文件中设置其他环境变量。

The Terminal loads a number of files that can modify your PATH variable, including ~/.profile, ~/.bashrc, ~/.bash_profile, etc. These do not get loaded when the Mac OS X system UI is started / when you login to your user profile via the Finder app. Consequently, apps started via Finder do not inherit the PATH and other environment variables set in these files.

不同版本的Mac OS X具有用于设置环境变量,使得它们通过搜索加载不同的解决方案。 Mac OS X中的旧版本支持一个名为〜/ .MacOSX / environment.plist 可用于指定环境。 OS X的新版本使用 launchctl 工具设置由应用程序看到的环境变量开始与 launchctl (这是负责启动系统的用户界面和其它系统服务)。

Different versions of Mac OS X have different solutions for setting environment variables such that they are loaded by Finder. Older versions of Mac OS X supported a file called ~/.MacOSX/environment.plist that could be used to specify the environment. Newer versions of OS X use the launchctl tool to set environment variables that are seen by apps started with launchctl (which is responsible for starting the system UI and other system services).

总之,使用命令:

launchctl setenv <variable-name> <variable-value>

要设置这个环境变量为当前用户。运行作为当前用户应用程序将继承指定的变量。因此,举例来说,你可以这样做:

To set this environment variable for the current user. Apps run as the current user will inherit the variables that are specified. So, for example, you could do:

launchctl setenv PATH "$PATH"

...从终端到当前路径值适用于系统为您的帐户。

... from the Terminal to apply your current PATH value to the system for your account.

另请参阅:

  • How to set the path for finder launched applications - StackExchange
  • launchctl man page - Mac OS X Darwin Reference

这篇关于Mac OS X的/斌/ bash中:蟒蛇:命令在某些IDE未找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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