Ubuntu Python一些有用的tips

1. Ubuntu下打開PyCharm

打開pycharm安裝目錄的bin目錄下,右擊選擇“Open in Terminal”,即可打開pycharm

2. Ubuntu 安裝所需程序包

國內的一些鏡像源地址

	  Python官方 https://pypi.python.org/simple/
	  阿里雲 https://mirrors.aliyun.com/pypi/simple/
	  豆瓣(douban) http://pypi.douban.com/simple/
	  清華大學 https://pypi.tuna.tsinghua.edu.cn/simple/
	  中國科學技術大學 http://pypi.mirrors.ustc.edu.cn/simple/
	  中國科學院 http://pypi.mirrors.opencas.cn/simple/
      v2ex http://pypi.v2ex.com/simple/

安裝方法:

pip install -i 鏡像源地址 + package

以從豆瓣安裝numpy爲例:

pip install -i https://pypi.doubanio.com/simple numpy

從requirements.txt安裝package方式:

pip install -i https://pypi.doubanio.com/simple -r requirements.txt

3. Ubuntu 新建虛擬環境

符號"$"表示Ubuntu系統的終端(Terminal)命令提示符,其後是需要運行的指令,例如:

user@ubuntu:~$ sudo apt-get install python3-pip python3-dev python-virtualenv  # for Python 3.n

其中"user"是用戶名,“ubuntu"是計算機名,命令名是"apg-get”,命令名前面的"sudo"表示以管理員權限運行命令"apg-get"(運行命令前會要求輸入用戶密碼)。

在Ubuntu 16.04系統下,打開一個終端,按照下述步驟安裝程序。

  1. 更新Ubuntu系統,依次運行下面兩條指令
    user@ubuntu:~$ sudo apt-get update
    user@ubuntu:~$ sudo apt-get upgrade
  1. Install pip3 and virtualenv
user@ubuntu:~$ sudo apt-get install python3-pip python3-dev python-virtualenv  # for Python 3.n
  1. Install Virtualenv and activate it

    3.1) Install Virtualenv

    user@ubuntu:~$ virtualenv -p python3.5 ~/venv/tf1132 # for Python 3.5  #
        或者
    user@ubuntu:~$ virtualenv --python=python3.5 ~/venv/tf1132 # for Python 3.5  #
    

    其中-p python3.5或–python=python3.5(也可以使用-p python3或–python=python3)指定創建虛擬環境時使用的python版本(該版本必須是已經安裝在系統裏的python版本)。如果去掉這個參數,就會使用系統默認的python。最後一個參數~/venv/tf1132是保存虛擬環境文件的文件夾,"tf1132"是虛擬環境的名字。python虛擬環境中的python版本與創建虛擬環境時使用的系統python版本一致!Ubuntu 16.04自帶的Python版本是3.5

    3.2) Activate Virtualenv

    user@ubuntu:~$ source ~/venv/tf1132/bin/activate
    

激活虛擬環境tf1132之後,終端的命令提示符由

user@ubuntu:~$

變換爲:

(tf1132) user@ubuntu:~$
  1. Update pip to the latest version
(tf1132) user@ubuntu:~$ pip install --upgrade pip
  1. Install tensorflow 1.13.2
(tf1132) user@ubuntu:~$ pip install --upgrade link_or_path_to_tensorflow_whl_file

安裝tensorflow的過程中,還需要下載安裝其它pythong包,比較大的包括:tensorboard,numpy等。如果安裝失敗,可以用wget -c將相應的包下載到本地再安裝。

  1. Validate your installation

    Activate the virtualenv environment and invoke python:

     (tf1132) user@ubuntu:~$ python
    

    Enter the following short program inside the python interactive shell:

     >>> import tensorflow as tf
     >>> hello = tf.constant('Hello, TensorFlow!')
     >>> sess = tf.Session()
     >>> print(sess.run(hello))
    

    If the system outputs the following, then you are ready to begin writing TensorFlow programs:
    b’Hello, TensorFlow!’

  2. Install other tools

    7.1) BeyondCompare
    Terminal Install - Debian, Ubuntu

         user@ubuntu:~$ sudo apt-get update
         user@ubuntu:~$ sudo apt-get install gdebi-core
         user@ubuntu:~$ sudo gdebi bcompare-4.2.9.23626_amd64.deb
    
     Terminal Uninstall
    
         user@ubuntu:~$ sudo apt-get remove bcompare
         user@ubuntu:~$ sudo apt-get remove bcompare:i386
    
     破解30天試用期方法:
         user@ubuntu:~$ sudo rm ~/.config/bcompare/*
             or
         user@ubuntu:~$ sudo rm ~/.config/bcompare/registry.dat    
    

    7.2) UltraEdit

     破解30天試用期方法:
         user@ubuntu:~$ rm -rfd ~/.idm/uex && rm -rf ~/.idm/*.spl && rm -rf /tmp/*.spl
    
         一定要刪除/tmp/*.spl和~/.idm/*.spl文件,否則試用期無法復位。
    

    7.3) PyAudio

     user@ubuntu:~$ sudo apt-get install libasound-dev portaudio19-dev
     user@ubuntu:~$ sudo apt-get install python-pyaudio python3-pyaudio
     user@ubuntu:~$ pip install pyaudio
    

    7.4) Install matplotlib

     user@ubuntu:~$ sudo apt-get install python3-tk
     user@ubuntu:~$ pip install matplotlib
    

    7.5) Install notepadqq

     user@ubuntu:~$ sudo snap install notepadqq
     
     # If you’re running Ubuntu 16.04 LTS (Xenial Xerus) or later, including 
     # Ubuntu 18.04 LTS (Bionic Beaver), Ubuntu 18.10 (Cosmic Cuttlefish) and 
     # Ubuntu 19.04 (Disco Dingo), you don’t need to do anything. Snap is 
     # already installed and ready to go
    

    7.6) Install sox

     user@ubuntu:~$ sudo apt-get install libasound2-plugins libasound2-python libsox-fmt-all
     user@ubuntu:~$ sudo apt-get install sox
    

    7.7) Install samba, htop, git, gitk, ncdu, unity tweak tool, unrar, 7zip
    $ sudo apt-get update
    $ sudo apt-get install samba htop git gitk ncdu unity-tweak-tool unrar p7zip-full p7zip-rar

END

######################################################################
######################################################################

  1. Install pip3 on Ubuntu 16.04
    $ sudo apt-get install python3-pip # for Python 3.n
    Verify the pip3 Installation on Ubuntu
    $ pip3 -V

    Install pip on Ubuntu 16.04
    $ sudo apt-get install python-pip # for Python 2.7
    Verify the pip Installation on Ubuntu
    $ pip -V

  2. Install pip and virtualenv
    $ sudo apt-get install python-pip python-dev python-virtualenv # for Python 2.7
    Install pip3 and virtualenv
    $ sudo apt-get install python3-pip python3-dev python-virtualenv # for Python 3.n

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章