PythonAnywhere-没有名为'pyvirtualdisplay'的模块

问题描述 投票:1回答:1

我正在尝试在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 pythonanywhere pyvirtualdisplay
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.