Use Idea to build python compiler and runtime environment


Intellij Idea is a Java language development environment integration, but its flagship version, after the transformation of the future can become the ideal IDE in the world today the vast majority language.

Now let's talk about how to use it to build the python IDE.
Of course, you can also use other tools pycharm directly, but I skilled idea, so I used it for multilingual development.

1.python download

https://www.python.org/downloads/

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly downAppData/Local/Temp/

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down 1580910801686.png
during installation, it may be wrong:
Python Installation failed: Service Pack 1 is required to continue installation
, please refer to: HTTPS: // Blog .csdn.net / u010565545 / article / details / 104218655

2. First enter Intellij Idea's official website: Click to open the link (omitted downloaded)

https://www.jetbrains.com/idea/

Click the download, select Ultimate download. Many online crack tutorial, students can also sign up for a free trial account to get the right year.

Not elaborate installation process, first opened choose your favorite configuration, and then enter the main interface.

Click File-> Settings ... -> Plugins, search python inside, as shown below:

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down1580908282642.png

发现搜索并没有结果。我们点击search in repositories链接,如下图所示:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传1580908318631.png

查询结果很多,哪个是我们需要的呢?由于我们所需要的是对一个语言(python)的支持,于是就在搜索框旁边的category下拉栏中选择Languages一项,选择如下的插件安装:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传1580908349739.png

点击旁边绿色的install,稍等片刻即可完成安装。安装完成后原本的install按钮变成了restart,说明需要重启Intellij Idea。点击按键即可重启。

这样,python的插件就安装完成了。

接下来是项目的配置方法
点击工具栏中的File->New->Project,可以看到左边的项目类型中多了一个python。点击它,如下图所示:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传1580908479004.png

如果你的电脑中已经安装过了python的环境,它会自动检测SDK。如果没有安装,这里推荐使用Anaconda,安装与配置方法请移步python神器——Anaconda。

配置系统全局Python环境

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传1580912214902.png

新建项目以后,右击左侧项目文件,选择新建python文件即可。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传1580908512112.png
4. 关于pip

img

  1. 如果上面的错误,则是没有引入urllib的包,需要通过pip进行引入。
  2. pip引入的命令为pip install urllib ,默认安装在C:\Python27\Lib\site-packages
  3. pip未安装,则进入命令行,然后把目录切换到python的安装目录下的Script文件夹下,运行 easy_inatall pip。
    这样就可以引入python的package。

注意
这里的python文件都必须要有明确的程序入口才能执行,不像自己随便写写的一个print一样。也就是说,必须要有 if name == ‘main’: 才行。如java的main方法

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传1580917853928.png

这样,在左边的行号栏就会出现运行符号,点击即可运行。

此外,由于这个IDE非常严谨,会在很多地方给你警告,比如你用了驼峰命名法(比如命名为studentName而不是student_name),或者两个函数间没有空出两行等。这些警告会有波浪下划线,有时候已经习惯了某种无害的写法,但就是看这个波浪线不爽,就可以点击画波浪线的地方,旁边会弹出一个小灯泡,选择无视这种问题就可以让波浪线消失了。如下图是两个函数间只空了一行的情况:

img

点击Ignore error like this,以后再有这种情况,它也会装作没看见了。要注意的是,只有无害的写法才能用这种方式忽略,否则灯泡里会有不同的选项,可以自行研究。

Something else
Intellij Idea是一个非常优秀的IDE,但是JetBrains好像不希望客户利用插件来使其成为一个万能的IDE,于是它先后推出了Clion、Pycharm、Datagrip等重磅产品,都是精品,并着重于自己分内的语言工作。2015年之前还能在Intellij Idea的仓库里找到C/C++的插件,但是自那以后就再也不更新了,既不兼容,也无法通过上述安装插件的方式找到了。不知道python这个插件还能活几年,能用几年是几年吧!个人觉得集成式的IDE还是相当爽的。

Python 基本语法参考:

https://www.runoob.com/python/python-tutorial.html

创建第一个Python工程

file >> New Project selected Python project

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down1580919968717.png

Create a Python file

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down1580919735440.png

Edit and run the program

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down1580920314027.png

result:

[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down1580920336690.png

Import the required libraries

In the windows system, just enter the command pip install requests, can be installed.

  在 linux 系统下,只需要输入命令 sudo  pip install requests ,即可安装。

  注:关于python第三方库的安装最好少使用 easy_install,因为 easy_install 只能安装不能卸载,如果要卸载需要进入到 python 的安装目录下面的 lib 的文件夹下手动删除对应的模块内容。所以建议多用 pip 的方式安装,安装时,用 pip install + 模块名称  命令来安装,卸载时,用 pip uninstall +模块名称 命令来删除。

  由于在国内使用 pip 或者 easy_install 安装时经常会撞墙,
  下面着重介绍另外的安装方法。

  1).  下载requests

        打开这个网址, http://www.lfd.uci.edu/~gohlke/pythonlibs 在这个网站上面有很多 python 的第三方库文件,我们按 ctrl+f 搜索很容易找到 requests 。如下图,

img

           点击那个 .whl 文件然后下载下来。

  2).  将 .whl文件下载下来后,将文件重命名,将后缀名从 .whl 改为 .zip ,然后解压文件,我们可以得到两个文件夹,如下图,

img

          我们将第一个文件夹,也就是 requests 文件夹复制到 python 的安装目录下的 lib 目录下。

  3). 到这里,requests 已经安装完毕,我们可以输入 import requests 命令来试试是否安装成功,

img

          如上图所示,import requests 没有报错,说明 requests 已经成功安装了。

2.pip domestic mirroring configuration python

1).常见国内镜像源
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 清华
http://mirrors.aliyun.com/pypi/simple/ 阿里
http://pypi.douban.com/simple/ 豆瓣
http://pypi.hustunique.com/simple/ 华中理工大学
http://pypi.sdutlinux.org/simple/ 山东理工大学
http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学

2).使用方法
2.1 临时生效使用方法
sudo pip install -i http://pypi.douban.com/simple/ flask

2.2  要配制成默认的话,需要创建或修改配置文件(linux的文件在~/.pip/pip.conf,windows在%HOMEPATH%\pip\pip.ini),修改内容为:

[global]
index-url = http://pypi.douban.com/simple

k

2.2 To be formulated into default, then you need to create or modify configuration files (linux files in ~ / .pip / pip.conf, windows in% HOMEPATH% \ pip \ pip.ini), modify the content as follows:

[global]
index-url = http://pypi.douban.com/simple



 
Published 28 original articles · won praise 26 · views 20000 +

Guess you like

Origin blog.csdn.net/u010565545/article/details/104218643
Recommended