Ubuntu12.04安装PyCharm
1. 下载
选择Linux Tab,选择下载免费的Community Edition【1】。当前版本是3.4
2. 安装PyCharm
按照官⽹给出的安装指导【2】进⾏安装。
(1) Copy the pycharm-*. to the desired installation location (make sure you have rw permissions for that directory)
$ cd Downloads/
(2)Unpack the pycharm-*. using the following command: tar xfz pycharm-*.
$ tar xfz pycharm-*.
(3)Remove the pycharm-*. to save disk space (optional)
$ rm  pycharm-*.
(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:
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.
(2) 初始设置,保持默认->OK.
(3) 创建⼀个Launcher脚本,需要输⼊密码。
(4)出现下⾯的画⾯,表明安装成功了。
(5) Create New Project,创建⼀个测试⼯程,解释器默认选择了Python2.7。
然后在新创建的⼯程上:点右键->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
java设置环境变量的方法代码
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;
然后双击打开,再锁定到启动器就好了.
Reference

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。