如何在python3.6文件夹中安装python包?

如何在python3.6文件夹中安装python包?

提取 .tar.gz 并运行后python setup install,selenium 将被安装在,

....
creating /usr/local/lib/python2.7/dist-packages/selenium-3.4.3-py2.7.egg
Extracting selenium-3.4.3-py2.7.egg to /usr/local/lib/python2.7/dist-packages
Adding selenium 3.4.3 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/selenium-3.4.3-py2.7.egg
.....

哪里python有 python 2.7,但没有 python3.6


跑步时,

$ python functionalTest.py 

它工作正常

$ python3.6 functionalTest.py

给出错误:

ModuleNotFoundError: No module named 'selenium'

因为我无法在 Ubuntu 上使用 python3.6 安装 selenium,所以成功了,如下所示,

$ ls setup*
setup.cfg  setup.py
$ python3.6 setup install
python3.6: can't open file 'setup': [Errno 2] No such file or directory
$ python3.6 setup.py install
Traceback (most recent call last):
  File "setup.py", line 22, in <module>
    from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'
.....
Original exception was:
Traceback (most recent call last):
  File "setup.py", line 22, in <module>
    from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'
$ 

安装后setuptools,以下是观察结果,

$ python3.6 setup.py install
.....
creating /usr/local/lib/python2.7/dist-packages/selenium-3.4.3-py2.7.egg
Extracting selenium-3.4.3-py2.7.egg to /usr/local/lib/python2.7/dist-packages
selenium 3.4.3 is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/selenium-3.4.3-py2.7.egg
Processing dependencies for selenium==3.4.3
Finished processing dependencies for selenium==3.4.3
$ cd /usr/local/lib/python
python2.7/ python3.5/ python3.6/ 
$ 
$ easy_install --version
setuptools 20.7.0 from /usr/lib/python2.7/dist-packages (Python 2.7)
$ pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$

问题:

1)为什么要在中安装 selenium、easy_install 和 pip /usr/local/lib/python2.7/dist-packages?我需要在中安装这些包/usr/local/lib/python3.6/dist-packages

2)如何配置python3.6来选择selenium?

3)为什么python --version不显示蟒蛇3.6除非明确询问python3.6 --version

答案1

  1. 给定包的名称(selenium-3.4.3-py2.7.egg) 这是适用于 Python 2.7 的包。查找适用于 Python 3.6 的包。
  2. 安装适合 Python 3.6 的软件包
  3. 因为大多数 Linux 发行版默认python仍然是 2.7,因为有很多脚本是为 2.7 编写的

在我的 Ubuntu 16.04上,python3来自存储库的软件包是 Python 3.5.3 ( sudo apt install python3)。 也可以从存储库安装 Selenium ( sudo apt install python3-selenium)。

相关内容