Python learning journey: virtualenv created using the Python environment and PyQT5 environment configuration

I, EDITORIAL

  Python from the first day of school, I knew pip using the command to install the package, from reptile to learn learning Web development, more and more libraries installed, from requests to lxml, from Django to Flask, variety the libraries are located in a Python environment.

  This practice is for my kind of lazy, but right then, but this also be a problem. The first problem is that Pycharm loading speed becomes slow because too many packages to be imported, while many packages for many who do not have access program. The second problem is that between many modules are required version, requires a specific version to run. One might argue that to install that particular version is not good enough? However, if the need to do it every time? Would not have to spend too much time Well, it is time to learn to use virtualenv down to create a set of "isolated" Python runtime environment for our application!

 

Second, the use virtualenv

1. Download

  Since you want to use virtualenv, it was certainly the first step in the installation, use pip to install.

pip install virtualenv

2. Create the environment  

  You need to find a folder used to store environment created (for example: my_env), then use the following command to create virtualenv environment, the command has a --no-site-packages parameter, use this parameter will not be system environment some packages have been copied, of course, there will be several such as pip based package. In addition, if your system has been installed multiple versions of Python, Python version can also be specified by the incoming path. Finally, you need to pass a name to create the Python environment named, I am using here is for_pyqt, it is clear that the environment created by the PyQT5.

  The final command is:

virtualenv --no-site-packages for_pyqt

  The figure below is a screenshot of running time:

  

3. Install third-party packages

  Now the environment has been created, you can have a look what documents:

  

   To install third-party packages, but also need to switch from the Python environment system into the Python environment we have created. Specific steps into the Scripts folder, execute activate command, as follows:

  

   You can see the beginning has become for_pyqt, it has been shown that switching to Python environment created, and then you can happily use pip install a third-party package!

 4. Use the Python environment created

  Where we talk about how to use Pycharm import Python environment we have created.

  Open in Pycharm set, and then add the python interpreter, create an empty folder (for example: venv), then the path to Python environment created add to the mix, and finally click "OK" and you're done.

   

 

Three, PyQT5 environment configuration

1. Why is PyQT5?

  If you had written in Python GUI, what would you use it? Python comes with tkinter? Or WxPython? Or is PyQT5?

  Here, I first want to eliminate is that there tkinter, for two reasons, one is cumbersome to use, the interface difficult to use, the second is made out of interface color values ​​are really low! That WxPython and PyQT5 compare it?

  First, both of which are based on C ++ development, and are cross-platform, the development of interfaces are also still beautiful, but PyQT5 more flexible, individual components can achieve a lot of features with a flexible, WxPython performance in this area is not too good. So finally I chose PyQT5, though it is installed it is really a lot of trouble!

2.PyQT5 installation

  PyQT5 to use, in addition to the need to install this package PyQT5, also you need to install a packet to support PyQT5: pyqt5-tools. So install command is:

pip install PyQT5

pip install pyqt5-tools

  These two packages installed, it might take a long time, so you will need to have a little patience ==

3.PyQT5 Configuration

  这里还是以 Pycharm 为例来说下 PyQT5 的环境配置。选择"File" => "Settings" => "Tools" => "External Tools",然后点击“+”,进行如下配置:

  

   

   主要就是把 designer.exe 和 pyuic5.exe 的路径加进去,这里给出我的路径以供参考:

E:\Pycharm\my_env\for_pyqt\Lib\site-packages\pyqt5_tools\Qt\bin\designer.exe

E:\Pycharm\my_env\for_pyqt\Scripts\pyuic5.exe

  完成上述操作之后,应该就能看到添加的工具了,如下图:

  

 4.环境验证

  首先点击 QtDesigner 创建一个应用,然后保存下来,再在 Pycharm 中右键点击该文件后选择 “PyUIC”,如果出现如下情况,那么恭喜你,你的环境就装好了!

  

   至于为什么会出现上面的报错信息,我觉得是因为没有指明文件路径。解决办法就是在命令行中使用如下命令(以test.ui为例):

pyuic5 -o ui.py test.ui

  该命令不报错的话就会生成一个 ui.py 了,然后你就可以愉快地使用 PyQT5 开发属于你的应用了!

Guess you like

Origin www.cnblogs.com/TM0831/p/11488892.html