码迷,mamicode.com
首页 > 编程语言 > 详细

Ubuntu系统Python3相关环境或模块安装

时间:2018-02-06 01:21:36      阅读:475      评论:0      收藏:0      [点我收藏+]

标签:准备   web   clone   配置环境变量   home   reading   bit   点击   crash   

前提:一般用户安装都命令前都需要sudo ,或者在root用户下

1、Ubuntu 16.04 安装PyCharm

  •     Ubuntu 16.04 安装PyCharm

   本文通过第三方源安装PyCharm,好处是升级方便。

   添加源:
   $ sudo add-apt-repository ppa:mystic-mirage/pycharm

   安装收费的专业版:
   $ sudo apt-get update
   $ sudo apt-get install pycharm

   安装免费的社区版:
   $ sudo apt-get update
   $ sudo apt-get install pycharm-community
   $ sudo apt remove pycharm pycharm-community && sudo apt autoremove

  不用配置环境变量,在终端随时可以启动pycharm-community来打开pycharm IDE

  • pycharm切换python2 和python3

    选择pycharm View——勾选Toolbar;点击工具栏中的扳手状的图标——project Interpreter中切换

2、ubuntu16.04 安装git:

  apt-get install git

  git init

      初始化空的 Git 仓库于 /home/linuxidc/python3_1000/.git/

  git clone https://github.com/Ranxf/1000(将git上已有项目或脚本clone到本地)

3、Ubuntu16.04安装pip:

  apt-get install python3-pip

4、Ubuntu16.04安装pytest:

  pip3 install pytest

  pytest --version(版本查看),结果This is pytest version 3.2.3, imported from /usr/local/lib/python3.5/dist-packages/pytest.py

5、Ubuntu16.04 安装selenium(安装好后的目录 /usr/local/lib/python3.5/dist-packages/)

  root@xzrs:/usr/bin# pip3 install selenium或python3 -m pip install selenium自动安装最新版本senlenium-3.6.0

如果之前安装的是selenium2,执行升级安装

  pip install --upgrade selenium 

 

  查看selenium版本方法:

  python Console下:

  >>>import  selenium
  >>>print(selenium.__version__)
   3.6.0

Webdrive 支持firefox(geckodriver),chrome(chromedrive),IE(驱动)及Opera(驱动)。各浏览器驱动下载地址http://www.seleniumhq.org/projects/webdriver/

6、Ubuntu16.04 手动安装firefox任何版本

  本次系统安装后,Firefox版本为51.0.1(64-bit)。

如果你想在 Ubuntu 中手动下载最新版本的 Firefox,进入它的下载页面。通过它你将可以获取到最新版本并安装它。

如果你想从初始版本安装其它版本的 Firefox,访问这个页面。在这你将看到从0.8开始的每个版本。

下载完你想要的版本之后,切换到 home 目录下的下载文件夹,因为 Ubuntu 的大多数文件被下载到了这里。

配置 Firefox

由于大多数 Firefox 下载文件以.tar和.bz2格式保存,必须从这些压缩包中提取文件。有很多方法可以在 Ubuntu 中解压缩文件。

比如我下面使用的命令。很容易从.tar和.bz2中提取文件。

    1. tar -xvf firefox*.tar.bz2

解压后,将会有一个新的 Firefox 文件出现在下载文件夹中。这其中包含了所有的 Firefox 的文件和可执行文件。

由于我们不想删除当前安装的 Firefox,我们必须给每个版本的 Firefox 创建一个单独的文件夹。因此,对于 Firefox 版本30,使用下面的命令在/opt目录下创建一个包含新 Firefox 内容的文件夹。

    1. sudo mv firefox/ /opt/firefox55

现在,/opt/firefox55/目录包含的所有文件都是版本30的。

创建新的 Firefox 可执行符号链接

默认情况下,Firefox 的可执行文件在这个路径下:/user/bin/firefox。我们想要做的是临时创建一个备份,这样我们就可以使用我们的自定义安装的可执行文件。

要做到这一点,运行下面的命令。

    1. sudo mv /usr/bin/firefox /usr/bin/firefox-old

现在,我们已经从其默认位置移动了 Firefox 的可执行文件,我们必须将默认位置链接到我们新的自定义安装文件。要做到这一点,运行下面的命令来创建我们版本55的一个符号链接。

    1. sudo ln -s /opt/firefox55/firefox /usr/bin/firefox

这样就设置完成了,我们自定义安装的 Firefox 是 Ubuntu 默认的。每一次启动 Firefox,它将通过之前的新链接加载新的可执行文件。

7、Ubuntu16.04 手动安装geckodriver。

下载geckodriver地址 https://github.com/mozilla/geckodriver/releases/ 

  • 文件下载到home/下载目录下;
  • cd 下载,tar -xvf geckodriver-v0.19.1-linux64.tar.gz;
  • cp geckodriver /usr/bin/
  • chmod +x geckodriver

本次使用的firefox版本55,配套geckodriver为v0.19.1。

 8、Ubuntu16.04安装chrome方法:

  • wget -c https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 如图:
     
    \--2017-11-03 11:22:42--  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    正在解析主机 dl.google.com (dl.google.com)... 203.208.43.70, 203.208.43.78, 203.208.43.64, ...
    正在连接 dl.google.com (dl.google.com)|203.208.43.70|:443... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度: 48725174 (46M) [application/x-debian-package]
    正在保存至: “google-chrome-stable_current_amd64.deb”
    
    google-chrome-stabl 100%[===================>]  46.47M  3.88MB/s    in 11s     
    
    2017-11-03 11:22:54 (4.04 MB/s) - 已保存 “google-chrome-stable_current_amd64.deb” [48725174/48725174])
     
  • dpkg -i google-chrome-stable_current_amd64.deb如图:
     
    root@linuxidc:/opt# sudo dpkg -i google-chrome-stable_current_amd64.deb
    sudo: 无法解析主机:linuxidc: 连接超时
    (正在读取数据库 ... 系统当前共安装有 222840 个文件和目录。)
    正准备解包 google-chrome-stable_current_amd64.deb  ...
    正在将 google-chrome-stable (62.0.3202.75-1) 解包到 (62.0.3202.75-1) 上 ...
    正在设置 google-chrome-stable (62.0.3202.75-1) ...
    正在处理用于 desktop-file-utils (0.22-1ubuntu5.1) 的触发器 ...
    正在处理用于 gnome-menus (3.13.3-6ubuntu3.1) 的触发器 ...
    正在处理用于 bamfdaemon (0.5.3~bzr0+16.04.20160824-0ubuntu1) 的触发器 ...
    Rebuilding /usr/share/applications/bamf-2.index...
    正在处理用于 mime-support (3.59ubuntu1) 的触发器 ...
    root@linuxidc:/opt# 
     

    则可以从应用程序中启动chrome和锁定到启动栏。

如果安装过程中有如下错误:

如显示以下类似文字

Selecting previously unselected package google-chrome-stable.
(Reading database ... 154656 files and directories currently installed.)
Preparing to unpack google-chrome-stable_current_amd64.deb ...
Unpacking google-chrome-stable (50.0.2661.86-1) ...
dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on libappindicator1; however:
Package libappindicator1 is not installed.

dpkg: error processing package google-chrome-stable (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5) ...
Processing triggers for mime-support (3.59ubuntu1) ...
Errors were encountered while processing:
google-chrome-stable

则执行

sudo apt-get install

此时如显示

Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run ‘apt-get -f install‘ to correct these.
The following packages have unmet dependencies:
google-chrome-stable : Depends: libappindicator1 but it is not installed
E: Unmet dependencies. Try using -f.

则執行

sudo apt-get install -f

完毕后重试以下命令,即可成功安装chrome

sudo dpkg -i google-chrome-stable_current_amd64.deb

9、Ubuntu16.04安装chrome驱动方法

如果要只用IE或者Chrome浏览器运行Web自动化用例,则需要先安装相应的浏览器驱动。要注意的是不同版本浏览器也对应不同版本的驱动,下载地址http://chromedriver.storage.googleapis.com/index.html选择对应版本进行安装。
我浏览器的版本为:版本 62.0.3202.75(正式版本) (64 位),我下载的驱动为V2.33。
 
----------ChromeDriver v2.33 (2017-10-03)----------
Supports Chrome v60-62
Resolved issue 2032: ChromeDriver crashes while creating DNS resolver [[‘Pri-1‘]]
Resolved issue 1918: Get/SetWindowSize & Get/SetWindowPosition commands are failing on Chromev62+ [[‘Pri-1‘]]
Resolved issue 2013: Android 8.0.0 webviews not supported [[‘Pri-2‘]]
Resolved issue 2017: In mobileEmulation "element is not clickable" if it is outside the visible area [[‘Pri-2‘]]
Resolved issue 1981: chromedriver does not respect excludeSwitches flag [[‘Pri-2‘]]
Partially Resolved issue 2002: Add Cookie is not spec compliant [[]]
Resolved issue 1985: FindElement raises the wrong error [[]]
 

下载完成后解压文件:

root@linuxidc:/home/linuxidc/下载# unzip chromedriver_linux64.zip
Archive:  chromedriver_linux64.zip
  inflating: chromedriver 

然后把他放到/urs/bin下面即可

root@linuxidc:/home/linuxidc/下载# cp chromedriver /usr/bin/

测试是否成功

可以编写以下代码进行测试:

技术分享图片

Ubuntu系统Python3相关环境或模块安装

标签:准备   web   clone   配置环境变量   home   reading   bit   点击   crash   

原文地址:https://www.cnblogs.com/wu-chao/p/8419857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!