我正在尝试在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)
所以该模块应该已经安装,但是当我尝试导入它时,我得到了第一个错误......我该如何解决这个问题?
答案 0 :(得分:0)
只需转到Web选项卡并找到Virtualenv设置,然后回到Web选项卡本身,在Virtualenv部分中编辑您的virtualenv路径。您可以指定完整路径/home/myusername/.virtualenvs/myproject,也可以仅指定virtualenv,myproject的简称,提交后系统会自动将其扩展为完整路径。