問題描述
我最近購買了一臺(tái) MacBook,并通過 Anaconda 在其上安裝了 Python.這是版本信息:
I recently bought a MacBook and install Python on it via Anaconda. Here's the version information:
Python 2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Nov 11 2013, 10:49:09)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
我希望能夠做以下所有事情:
I'd like to be able do all of the following:
- 無需通過啟動(dòng)器應(yīng)用程序即可啟動(dòng) Spyder(例如,通過在 Spotlight 和 Quicksilver 中輸入內(nèi)容)
- 從 Finder 運(yùn)行 Python 代碼,大概是通過雙擊我的 .py 文件或選擇并按下 Cmd-O 來實(shí)現(xiàn)
- 通過在 Quicksilver 中輸入 Python 腳本的名稱來運(yùn)行 Python 代碼(就像它是一個(gè)常規(guī)程序一樣)
這是我嘗試過的:
- (什么都沒有;這里沒有想法)
- 我已將 .py 文件與/Users/kuzzooroo/anaconda/python.app/Contents/MacOS/python 相關(guān)聯(lián)并使其可執(zhí)行(chmod u+x).當(dāng)我嘗試運(yùn)行應(yīng)用程序時(shí),它永遠(yuǎn)不會(huì)啟動(dòng),并且我沒有收到錯(cuò)誤消息(不知道在哪里查看)
- 使文件可執(zhí)行并嘗試從 Spotlight 運(yùn)行它們.結(jié)果與 #2 相同.
這是我可以做的:
- 如果我在頂部有正確的 shebang 并且已使文件可執(zhí)行,則從終端窗口運(yùn)行我的代碼
- 使用 py2app 生成應(yīng)用程序.不幸的是,這種方法存在以下缺點(diǎn):
- 我經(jīng)常修改我的腳本,不希望每次都運(yùn)行 py2app
- 即使是一個(gè)簡單的腳本,生成的應(yīng)用程序也是 7 MB
- 要在某些情況下運(yùn)行應(yīng)用程序,我必須在包中四處尋找實(shí)際的Unix 可執(zhí)行文件"并運(yùn)行它
一旦我有這個(gè)工作,我有興趣做以下事情:
A. 控制哪些腳本在運(yùn)行時(shí)創(chuàng)建控制臺(tái)窗口,哪些不創(chuàng)建
B. 控制生成的控制臺(tái)窗口在腳本完成時(shí)是否消失或等待用戶(我)關(guān)閉它
但是,我懷疑一旦我首先弄清楚我將如何調(diào)用我的腳本,就很容易弄清楚如何執(zhí)行這些操作(或者是否可能).Once I have this working, I'm interested in doing the following:
A. Controlling which scripts create a console window when they run and which do not
B. Controlling whether the resulting console window disappears when the script completes or waits around for the user (me) to close it
However, I suspect it may be easy to figure out how to do these (or whether it's possible) once I've figured out how I'm going to invoke my scripts in the first place.推薦答案
使 spyder 可以從 Spotlight 或 Finder 中調(diào)用:
To make spyder callable from Spotlight or Finder:
通過在終端中運(yùn)行來定位您的 spyder 可執(zhí)行文件所在的位置:
Locate where your spyder executable is by running in Terminal:
which spyder
如果你通過 Anaconda 安裝了 spyder,這應(yīng)該產(chǎn)生
~/anaconda/bin/spyder
,如果你使用 MacPorts 或類似的東西,則產(chǎn)生/opt/local/bin/spyder
.This should yield
~/anaconda/bin/spyder
if you installed spyder via Anaconda,/opt/local/bin/spyder
if you used MacPorts or something similar.在您的
Applications
目錄中創(chuàng)建一個(gè)名為spyder
的文件并使其可執(zhí)行.然后,用上一個(gè)命令的輸出填充它,然后是&;退出
:Create a file called
spyder
in yourApplications
directory and make it executable. Then, fill it with the output of the previous command, followed by a&; exit
:touch /Applications/spyder chmod +x /Applications/spyder echo -e '#!/bin/bash'" ~/anaconda/bin/spyder & exit" >> /Applications/spyder
(如果你使用不同的 shell(例如
tcsh
),用那個(gè)替換bash
)(if you use a different shell (e.g.
tcsh
), replacebash
by that)在終端->首選項(xiàng)->配置文件->默認(rèn)配置文件"->外殼->當(dāng)外殼退出時(shí):選擇如果外殼干凈退出則關(guān)閉"
Under Terminal -> Preferences -> Profiles -> "default profile" -> Shell -> When the shell exits: Select "Close if the shell exited cleanly"
可選:
從這里下載spyder圖標(biāo)并打開在預(yù)覽中.按 cmd+C 復(fù)制其內(nèi)容.
Download the spyder Icon from here and open it in Preview. Copy its contents by hitting cmd+C.
在 Finder 中,找到
/Applications/spyder
并按 cmd+I 打開其獲取信息"窗格.用鼠標(biāo)選擇左上角的圖標(biāo),然后按 cmd+V.In Finder, locate
/Applications/spyder
and open its "Get Info" pane by hitting cmd+I. Select the icon in the top left corner with your mouse and hit cmd+V.這篇關(guān)于在 OSX 上調(diào)用 python 和 Spyder 的方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!