【问题标题】:PythonAnywhere - No module named 'pyvirtualdisplay'PythonAnywhere - 没有名为“pyvirtualdisplay”的模块
【发布时间】:2017-11-02 15:36:08
【问题描述】:

我正在尝试在 PythonAnywhere 上在线运行一个项目。当我调用这个函数时:

def getPrice(item_url):
    from forex_python.converter import  CurrencyRates
    from selenium import webdriver
    from pyvirtualdisplay import Display
    #from IPython.display import display
    with Display():
        browser = webdriver.Firefox()
    try:
        browser.get(item_url)
        item_price = browser.find_element_by_xpath("//SPAN[@class='market_table_value normal_price']").text
        #item_price isn't an integer, it's a string, 'Prezzo iniziale: $' and 'USD' need to be cut with .replace, then converted to int with int()
        #item_price_edited is the int() variable, ready to be used
        #price is the final value, ready for use
        item_price_cut1 = item_price.replace('Prezzo iniziale','')
        item_price_cut2 = item_price_cut1.replace('$','')
        item_price_cut3 = item_price_cut2.replace('USD','')
        item_price_edited_usd = float(item_price_cut3)
        #the value of the price is USD, it needs to be converted to EUR
        c = CurrencyRates()
        #round arrotonda il valore con la virgola a due numeri decimali
        price = round(c.convert('USD','EUR', item_price_edited_usd),2)
        browser.close()
        return price
    finally:
        browser.quit()

我收到此错误:

Traceback (most recent call last):
  File "/home/BobbyQ/mm/check.py", line 13, in <module>
    price = getPrice(item_url)
  File "/home/BobbyQ/mm/functions.py", line 6, in getPrice
    from pyvirtualdisplay import Display
ModuleNotFoundError: No module named 'pyvirtualdisplay'

所以我应该安装模块,但是当我运行时:

pip install pyvirtualdisplay

我明白了:

Requirement already satisfied (use --upgrade to upgrade): pyvirtualdisplay in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): EasyProcess in /usr/local/lib/python2.7/dist-packages (from pyvirtualdisplay)

所以模块应该已经安装了,但是当我尝试导入它时,我得到了第一个错误......我该如何解决这个问题?

【问题讨论】:

  • 您使用哪个版本的 Python 运行代码?
  • @GilesThomas Python 3.6
  • 你在使用 virtualenv 吗?如果是这样,您是否在 virtualenv 中运行您的代码?
  • 试试pip3.6 install --user pyvirtualdisplay

标签: python pythonanywhere pyvirtualdisplay


【解决方案1】:

只需转到 web 选项卡并找到 Virtualenv 设置然后,回到 web 选项卡本身,在 Virtualenv 部分中编辑 virtualenv 的路径。可以指定完整路径/home/myusername/.virtualenvs/myproject,也可以只指定virtualenv的简称myproject,提交后系统会自动展开为完整路径。

【讨论】:

    猜你喜欢
    • 2015-11-20
    • 2016-01-02
    • 2020-07-24
    • 2017-02-15
    • 1970-01-01
    • 2022-12-13
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    相关资源
    最近更新 更多