PythonAnywhere - No module named 'pyvirtualdisplay'

£可爱£侵袭症+ 提交于 2020-01-15 10:23:09

问题


I am trying to run online a project on PythonAnywhere. When I call this function:

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()

I get this error:

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'

So I should install the module, but when I run:

pip install pyvirtualdisplay

I get this:

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)

So the module should be already installed, but when I try to import it I get the first error...How can I fix this issue?


回答1:


Just go to web tab and find Virtualenv setting Then, back on the web tab itself, edit the path to your virtualenv in the Virtualenv section. You can specify the full path, /home/myusername/.virtualenvs/myproject, or just the short name of the virtualenv, myproject, and the system will automatically expand it to the full path after you submit it.



来源:https://stackoverflow.com/questions/47079146/pythonanywhere-no-module-named-pyvirtualdisplay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!