2015年5月10日 星期日

安裝pip

原本我安裝pip一直遇到問題

我原本參考網路上的文章大多數是使用

$ wget http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py

好的,我的mac沒有裝wget,所以我先找了文章參考怎麼裝wget,如下:


搞定好wget後我就執行 sudo python distribute_setup.py,但是一直出現問題。

  File "distribute_setup.py", line 1
   
    ^
SyntaxError: invalid syntax

上面那幾行我除了知道是語法有問題之外,其他的我根本就不知道是那裡錯。

只好先搞定mac 裡面python版本的問題,我希望事情可以單純一點。

還好上次詢問的專業人仕有寄資料來給我參考。

https://pip.pypa.io/en/latest/installing.html

真的是非常感謝好心的人。

目前我已安裝了pip,也安裝了cython

但是在安裝pip的時候有遇到了點問題

The directory '/Users/sgr918/Library/Logs/pip' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/Users/sgr918/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/Users/sgr918/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

不曉得上面是講什麼意思?是路徑要指來指去嗎?

再研究研究。



將mac的python2 改裝python3

其實我一直沒搞懂mac 的系統,在自已的mqc中裝了python2,也裝了python3。

最近我看了python.tw的影片想試一試cython,但是我裝軟體有一點問題。

我目前還沒有找到問題,我先一個一個修正。

最初的問題在於我沒有辦法安裝pip,我不曉得pip是不是只支援python2。

沒關係,我慢慢來搞懂。

我有寄信詢問網路上的專業人仕,不過我還沒操作他的方法。

這邊我先紀錄一下怎麼移除python2以及安裝python3

我在網路上參考這個網頁依照他的步驟操作已成功移除並設定mac python版本為3.3

下述內容均出自

如何将Mac OS X10.9下的Python2.7升级到最新的Python3.3




     第1步:下载Python3.3
     Python3.3  
     第2步:
     安装下载的文件,安裝後目錄如下:
/Library/Frameworks/Python.framework/Versions/3.3

第3步:移動python的安装目錄
所有的python安裝目錄都在
/System/Library/Frameworks/Python.framework/Versions
目錄中,所以最好使用下面的命令移动一下,當然不移動也可以。但後面步骤中的某些路径需要修改下。
sudo mv /Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions
     第4步:改变Python安装目录的用户组为wheel
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.3
     python2.7的用户组就是wheel,3.3也照葫芦画瓢吧!

     第5步:修改Python当前安装目录的符号链接
      在 /System/Library/Frameworks/Python.framework/Versions/目录下有一个Current,这是         一个目 录符号链接,指向当前的Python版本。原来指向2.7的,现在指向3.3。所以应先删除               Current。然后重新建立Current符号链接,命令如 下:
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions/Current

第6步:删除旧的命令符号链接

在/usr/bin目录下有4个python命令的符号链接,使用下面的命令先删除
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config

第7步:重新建立新的命令符号链接
将第6步删除的符号链接重新使用下面命令建立,它们都指向Python3.3了。
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/pydoc3.3 /usr/bin/pydoc
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/pythonw3.3 /usr/bin/pythonw
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3m-config /usr/bin/python-config

第8步:更新/root/.bash_profile文件中的路径
cd ~

vim .bash_profile 

在.bash_profile插入下面的内容即可

# Setting PATH for Python 3.3
# The orginal version is saved in .bash_profile.pysave
PATH="/System/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}"
export PATH

ok,现在重新启动一下Console,然后执行python --version,得到的就是Python 3.3.3。如果在程序中,需要使用下面代码获取python版本
1
2
import platform
print(platform.python_version())


如果还是用了如PyDev等IDE,仍然需要更新一下相关的路径。

现在可以使用最新的Python3.3.3了。