【问题标题】:How to install beautifulsoup into python3, when default dir is python2.7?当默认目录为python2.7时,如何将beautifulsoup安装到python3中?
【发布时间】:2016-04-03 03:25:02
【问题描述】:

我同时安装了 Python 2.7 和 Python 3.5。当我输入 pip install beautifulsoup4 时,它告诉我它已经安装在 python2.7/site-package 目录中。

但是如何将它安装到 python3 目录中呢?

【问题讨论】:

标签: python python-3.x beautifulsoup pip


【解决方案1】:

我认为 pip3 会满足您的需求,在终端上使用以下命令:

pip3 install beautifulsoup4

doc

【讨论】:

    【解决方案2】:

    以root身份运行:

    apt-get install python3-bs4
    #or
    pip3 install beautifulsoup4
    

    然后像这样导入它:

    import bs4
    

    【讨论】:

    • 你知道为什么它被安装为beautifulsoup4 并被称为bs4 吗?
    • @Mischief_Monkey 不,我不知道,但可能你不必写 import beautifulsoup4 as bs4 当你尝试从模块访问类时,它可以节省大量的输入,例如bs4.PageElement
    【解决方案3】:

    如果您使用的是最新版本的 Debian 或 Ubuntu Linux,您可以使用系统包管理器安装 Beautiful Soup:

    $ apt-get install python-bs4 (for Python 2)
    $ apt-get install python3-bs4 (for Python 3)
    

    安装后导入库

    from bs4 import BeautifulSoup
    

    【讨论】:

      【解决方案4】:

      包是bs4,可以使用以下命令安装:

      python -m pip install bs4
      

      【讨论】:

        【解决方案5】:

        我在 Python 版本和 Beautifulsoup 之间有些不匹配。我正在安装这个项目 Th3Jock3R/LinuxGSM-Arma3-Mod-更新 到 linux centos8 专用 Arma3 服务器。 Python3 和 Beautifulsoup4 似乎匹配。所以我更新了 Python3,手动删除了 Beautifulsoup 文件并重新安装:sudo yum install python3-beautifulsoup4(注意数字 3)。作品。只需在 Th3Jock3R:s 脚本 A3_SERVER_FOLDER = "" 和 A3_SERVER_DIR = "/home/arma3server/serverfiles/{}".format(A3_SERVER_FOLDER) 中指向目录并通过 python3 update.py在同一文件夹中运行脚本> 现在模组加载的轻盈让我大吃一惊。 -鲍勃-

        【讨论】:

          【解决方案6】:

          如果您在 Windows 上,这也适用于 Python3 py -m pip install bs4

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-03-15
            • 1970-01-01
            • 1970-01-01
            • 2014-08-02
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多