简体   繁体   English

PythonAnywhere - 没有名为“pyvirtualdisplay”的模块

[英]PythonAnywhere - No module named 'pyvirtualdisplay'

I am trying to run online a project on PythonAnywhere.我正在尝试在 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?所以模块应该已经安装了,但是当我尝试导入它时,我得到了第一个错误......我该如何解决这个问题?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM