我决定以后一直使用 Eclipse 了 因为它也可以安装集成 PyDec 插件来实现 Python 开发了 哇哈哈哈



Python
作为当今主流的爬虫编程语言,在我们的开发当中时不时都会使用到一些,那么如果你想再Eclipse
当中进行一些Python
的开发就要安装一下Python插件
这样就也用Eclipse
进行Python
的开发, 或者在java
相关的项目中使用Python代码
来混编项目, 所以首先我们要知道如何在Eclipse
中集成Python

Python 下载 🔻
这里我以win10系统
为例, 但是先要去下载Python
,否则后期你是无法在eclipse
中编译解释Python代码
的
官方地址: https://www.python.org/downloads/
这里我就下载最新的Python3.10.7
如图

下载好之后,是一个python-3.10.7-amd64.exe
的文件
如图


Python 安装 ❤️
在 windows 中安装Python
,其实很简单, 跟一般安装软件差不多!
这里直接点击下载好的python-3.10.7-amd64.exe
开始安装
然后选择自定义安装
方式
如图

继续默认下一步:

然后自己选择一个安装路径!
如图

然后点击Install
开始安装Python

完成Python
安装!

Python 环境变量的配置 📚
你安装Python
的路径很可能不在当前操作系统
提供可执行文件的搜索路径中, 也是Path
路径
配置这个环境变量
可以让系统轻松帮你找到Python
来执行!
在win10
中具体步骤为如下:
点击我的电脑右键---->属性---->高级系统设置---->选择高级选项卡---->环境变量
这里我们就选择系统变量
下的Path
进行编辑
如图

然后把你安装Python
的路径添加到Path
当中,这里我的路径为:D:\Python 3.10.7
最后点击确定即可!
如图

当然你也可以配置一个PYTHONHOME
的环境变量
也就是为了方便后期其他程序利于检索!
具体方法如下: 我们就在系统变量
当中来新建一个变量

点击新建
输入:PYTHONHOME
和安装路径, 然后确定
如图

然后选择Path
编辑它, 把%PYTHONHOME%
添加到其中即可!
如图

接着我们来测试一下,
按下快捷键Win+R
打开运行
, 并且输入cmd
调出命令提示符
,输入python
如图

如果出现上图提示 那么说明Python安装
就完成了!
PyDev 介绍 ℹ️
Eclipse
的安装我在前面已经详细说过了,还不清楚的朋友可以翻看前面的文章!
这里我主要来说一下如何安装PyDev插件
PyDev介绍
其实也就是可以让Eclipse
来进行Python
应用程序的开发和调试的一个插件
,而PyDev
能够将Eclipse
当作 Python IDE
来使用!
Eclipse 安装 Python 插件步骤 🌒
我们打开Eclipse
之后依次展开菜单栏: Help--->install New Software
如图

接着在弹出的Install
对话框中,点击右侧的Add
按钮
如图

然后在Name
和Location
中输入以下内容:
name
随便命名
Location
比如输入: http://www.pydev.org/updates
如图

输入完成后点击Add
按钮,Eclipse
就会通过输入的地址查找这个PyDev
插件
如果能够找到这个插件会出现以下所示:
如图

接着我们选中框中的所有选项,继续点击Next

继续默认一直(next)
下一步


在接下来弹出的对话框中勾选一下:
I accept the terms of the license agreements(我接受许可协议的条款)
然后点击Finish
如图

现在我们可以正确的自动下载安装Python
插件了 你只需要等待安装结束即可!
如图


这个时候可能会弹出trust(信任)
选项对话框
如图

那么就点击Select all
我这里就勾选以下Always trust all content(始终信任所有内容)
然后会弹出确定要不要
的对话框
如图

最后再点击Trust selected
就可以了!
然后安装完成了,就点击一下Restart now(现在重启)
即可!

Eclipse 配置 Python 解释器 🛰️
PyDev插件
安装成功后,还需要配置一下Python解释器
,不然Eclipse
无法正常执行Python代码
我们依次展开菜单栏: windows---->Preferences
然后在左侧导航栏选择PyDev---->Interpreters---->Python Interpreter
然后点击右侧的New...
选择里面的Config first in PATH
, 通过在Path
环境变量路径中的PYTHONHOME
我们可以找到Python.exe
这个解释器
,
注意:你前提条件是要先安装过Python
如图

当然如果你之前没有配置PYTHONHOME
环境变量也可以点击Browse for Python/pypy exe
按钮来手动找到 Python
安装路径下的解释器
接下来找到之后,点击Apply and Close(应用并关闭)
即可
如图

Eclipse 运行 Python 代码 🌐
一切就绪之后,我们现在就来使用Eclipse
运行一个简单的Python
程序Hello Wrold
通过Eclipse
新建一个Python
的Project(项目)
依次展开菜单栏: File---->New---->Project
然后选择PyDev
下的PyDev Project
然后点击Next
如图

接着在弹出的对话框中,输入Project Name(项目名称)
并且选择Create src folder and add it to PYTHONPATH
,其他保持默认即可!,
然后点击完成(Finish)
如图

接着点击Open Perspective

完成后可以仔细观察到,Eclipse
的右上角有一个Python
的小按钮,
说明已经切换到Python
的开发模式下!
如图

接下来跟java
类似我们可以在左侧的src
下,去建立Python
文件
在src
上右键
,选择New–---->File

在弹出的窗口填写File Name
文件名称加上.py
后缀 然后点击Finish完成
这里我新建一个test.py
如图

如果出现以下弹窗,点击OK
即可

那么就可以进行Python
代码的开发了
在test.py
中我们输入以下代码:
如图

然后点击菜单栏中的Run--->Run
来运行Python
如图

然后如果你是第一次运行,会弹出选择运行方式
对话框, 选择Python Run
就可以了,点击ok

最后我们终于可以利用Eclipse
来进行Python开发
了,哇哈哈哈哈! 🤪🤪🤪🤪🤪🤪
如图



"👍点赞" "✍️评论" "收藏❤️"
大家的支持就是我坚持下去的动力!
如果以上内容有任何错误或者不准确的地方,🤗🤗🤗欢迎在下面 👇👇👇 留个言指出、或者你有更好的想法,欢迎一起交流学习❤️❤️💛💛💚💚

版权声明: 本文为 InfoQ 作者【极客小俊】的原创文章。
原文链接:【http://xie.infoq.cn/article/c5517afe061c84d8021c20c6d】。未经作者许可,禁止转载。
评论