ubunto安装pycharm

转载:http://www.cnblogs.com/zhcncn/p/4027025.html

1. 下载

http://www.jetbrains.com/pycharm/download/

选择Linux Tab,选择下载免费的Community Edition【1】。当前版本是3.4

 

2. 安装PyCharm

按照官网给出的安装指导【2】进行安装。

(1) Copy the pycharm-*.tar.gz to the desired installation location (make sure you have rw permissions for that directory)

$ cd Downloads/

(2)Unpack the pycharm-*.tar.gz using the following command: tar xfz pycharm-*.tar.gz

$ tar xfz pycharm-*.tar.gz

(3)Remove the pycharm-*.tar.gz to save disk space (optional)

$ rm  pycharm-*.tar.gz

(4)Run pycharm.sh from the bin subdirectory

$ cd pycharm-community-3.4.1/bin/

$ ./pycharm.sh

但是安装开始,出现如下错误:

ERROR: Cannot start PyCharm

No JDK found. Please validate either PYCHARM_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation.

打开pycharm.ch文件查看,发现报错的地方在:

复制代码
message()
{
  TITLE
="Cannot start PyCharm"
  if [ -t 1 ]; then
    echo "ERROR: $TITLE\n$1"
  elif [ -n `which zenity` ]; then
    zenity --error --title="$TITLE" --text="$1"
  elif [ -n `which kdialog` ]; then
    kdialog --error --title "$TITLE" "$1"
  elif [ -n `which xmessage` ]; then
    xmessage -center "ERROR: $TITLE: $1"
  elif [ -n `which notify-send` ]; then
    notify-send "ERROR: $TITLE: $1"
  else
    
echo "ERROR: $TITLE\n$1"
  fi
}

# ---------------------------------------------------------------------
# Locate a JDK installation directory which will be used to run the IDE.
# Try (in order): PYCHARM_JDK, JDK_HOME, JAVA_HOME, "java" in PATH.
# ---------------------------------------------------------------------
if [ -n "$PYCHARM_JDK" -a -x "$PYCHARM_JDK/bin/java" ]; then
  JDK="$PYCHARM_JDK"
elif [ -n "$JDK_HOME" -a -x "$JDK_HOME/bin/java" ]; then
  JDK="$JDK_HOME"
elif [ -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
  JDK="$JAVA_HOME"
else
  JAVA_BIN_PATH=`which java`
  if [ -n "$JAVA_BIN_PATH" ]; then
    if [ "$OS_TYPE" = "FreeBSD" -o "$OS_TYPE" = "MidnightBSD" ]; then
      JAVA_LOCATION=`JAVAVM_DRYRUN=yes java | "$GREP" '^JAVA_HOME' | "$CUT" -c11-`
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    elif [ "$OS_TYPE" = "SunOS" ]; then
      JAVA_LOCATION="/usr/jdk/latest"
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    elif [ "$OS_TYPE" = "Darwin" ]; then
      JAVA_LOCATION=`/usr/libexec/java_home`
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    fi

    if [ -z "$JDK" -a -x "$READLINK" -a -x "$XARGS" -a -x "$DIRNAME" ]; then
      JAVA_LOCATION=`"$READLINK" -f "$JAVA_BIN_PATH"`
      case "$JAVA_LOCATION" in
        */jre/bin/java)
          JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"`
          if [ ! -d "$JAVA_LOCATION/bin" ]; then
            JAVA_LOCATION="$JAVA_LOCATION/jre"
          fi
          ;;
        *)
          JAVA_LOCATION=`echo "$JAVA_LOCATION" | "$XARGS" "$DIRNAME" | "$XARGS" "$DIRNAME"`
          ;;
      esac
      if [ -x "$JAVA_LOCATION/bin/java" ]; then
        JDK="$JAVA_LOCATION"
      fi
    fi
  fi
fi

if [ 
-z "$JDK"
 ]; then
  message 
"No JDK found. Please validate either PYCHARM_JDK, JDK_HOME or JAVA_HOME environment variable points to valid JDK installation."
  exit 1
fi
复制代码

说明没有找到JDK location path。需要安装并配置JDK了。

 

3. 安装JDK

首先查了一下Ubuntu12.04是否支持JDK8,发现还是支持的。那就放心安装吧。

参照【3】的方法,通过设置源仓库的方式安装。(如果想手动安装,请参考【5】【6】)

Important: This PPA supports Ubuntu 14.04, 13.10, 12.04 and 10.04 as well as the corresponding Linux Mint versions. Ubuntu 13.04 and 12.10 are no longer supported by Canonical

(1)返回到Home目录:“~”,然后依次执行一下几条command

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

安装过程中会跳出Oracle license对话框,选择接受就是了。

(2)安装完成后,运行"Java -version"或者"javac -version"查看是否安装成功。如果得到类似如下的输出,表明安装成功了。

$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ javac -version
javac 1.8.0_20

(3) 在【3】中说道,如果想automatically set up the Java 8 environment variables,可以使用下面的command:

http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html

sudo apt-get install oracle-java8-set-default

我使用该command后,在Terminal中运行 echo $JAVA_HOME,没有任何输出。看来是没起什么作用。有可能是在一开始配置完repository后,安装时使用该条命令,可以以后尝试一下。

UPDATED: 使用 sudo apt-get install oracle-java8-set-default,测试echo $JAVA_HOME,仍然是没有$JAVA_HOME环境变量的。还是需要手动设置。

由于一些程序在运行时可能默认需要 $JAVA_HOME 环境变量,因此还是需要设置一下环境变量的。

 

4. 配置$JAVA_HOME 环境变量

参考【4】中 Setting the "JAVA_HOME" environment variable 一节进行设置。

(1)Find out the path of your Java installation:

sudo update-alternatives --config java

它将返回类似如下的结果,列出了本机所安装的所有Java运行时环境JRE。(共有2个:JDK7和OpenJDK6,0和2是同一个,auto mode和manual mode的差别)

复制代码
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:
复制代码

对应的各个JRE的 安装路径分别为:

0. /usr/lib/jvm/java-7-oracle

1. /usr/lib/jvm/java-6-openjdk-amd64

2. /usr/lib/jvm/java-7-oracle

在我本机 执行 sudo update-alternatives --config java 的结果为:

Selection    Path                                     Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         auto mode
* 1            /usr/lib/jvm/java-8-oracle/jre/bin/java   1         manual mode

Press enter to keep the current choice[*], or type selection number:

可见只安装了一个Java环境: JDK8。它对应的安装路径为:

/usr/lib/jvm/java-8-oracle

(2)编辑/etc/environment文件

sudo nano /etc/environment

复制上面的路径 /usr/lib/jvm/java-8-oracle,添加如下一行

JAVA_HOME="/usr/lib/jvm/java-8-oracle"

(3) Reload该文件,使之立即生效,而不必注销并重新登录

source /etc/environment

(4)使用下面的命令测试

echo $JAVA_HOME

会输出刚才所设置的路径 /usr/lib/jvm/java-8-oracle。

5. 再次安装PyCharm

(1)cd到Downloads/pycharm-community-3.4.1/bin/目录,执行./pycharm.sh。询问是否导入settings,选择不导入->OK.

image

(2) 初始设置,保持默认->OK.

575D0ZC`9]VL5A8A@C)%)U8

(3) 创建一个Launcher脚本,需要输入密码。

image

用户名
yueting3527
注册码
===== LICENSE BEGIN =====
93347-12042010
00001FMHemWIs"6wozMZnat3IgXKXJ
2!nV2I6kSO48hgGLa9JNgjQ5oKz1Us
FFR8k"nGzJHzjQT6IBG!1fbQZn9!Vi
===== LICENSE END =====

(4)出现下面的画面,表明安装成功了。

]0RBN}ANEVT{8(BEG]Z{P0I

(5) Create New Project,创建一个测试工程,解释器默认选择了Python2.7。

`H2I[1FUMP~A`J}UQ``]%GG

然后在新创建的工程上:点右键->New->Python File, 创建一个新的文件Py01,写代码,点Run按钮->Run Py01运行。

 

6. 设置Ubuntu下Pycharm的快捷启动方式

在Ubuntu下,每次都要找到 pycharm.sh所在的文件夹,执行./pycharm.sh,非常麻烦。最好能创建一个快捷方式。【7】

Ubuntu的快捷方式都放在/usr/share/applications,首先在该目录下创建一个Pycharm.desktop

$ sudo gedit /usr/share/applications/Pycharm.desktop

然后输入以下内容,注意Exec和Icon需要找到正确的路径

复制代码
[Desktop Entry]
Type=Application
Name=Pycharm
GenericName=Pycharm3
Comment=Pycharm3:The Python IDE
Exec="/XXX/pycharm-community-3.4.1/bin/pycharm.sh" %f
Icon=/XXX/pycharm-community-3.4.1/bin/pycharm.png
Terminal=pycharm
Categories=Pycharm;
复制代码

然后双击打开,再锁定到启动器就好了.

 序列号:

  1. 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiIiwiYXNzaWduZWVFbWFpbCI6IiIsImxpY2Vuc2VSZXN0cmljdGlvbiI6IkZvciBlZHVjYXRpb25hbCB1c2Ugb25seSIsImNoZWNrQ29uY3VycmVudFVzZSI6ZmFsc2UsInByb2R1Y3RzIjpbeyJjb2RlIjoiSUkiLCJwYWlkVXBUbyI6IjIwMTctMDItMjUifSx7ImNvZGUiOiJBQyIsInBhaWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IkRQTiIsInBhaWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IlBTIiwicGFpZFVwVG8iOiIyMDE3LTAyLTI1In0seyJjb2RlIjoiRE0iLCJwYWlkVXBUbyI6IjIwMTctMDItMjUifSx7ImNvZGUiOiJDTCIsInBhaWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IlJTMCIsInBhaWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IlJDIiwicGFpZFVwVG8iOiIyMDE3LTAyLTI1In0seyJjb2RlIjoiUEMiLCJwYWlkVXBUbyI6IjIwMTctMDItMjUifSx7ImNvZGUiOiJSTSIsInBhaWRVcFRvIjoiMjAxNy0wMi0yNSJ9LHsiY29kZSI6IldTIiwicGFpZFVwVG8iOiIyMDE3LTA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