[英]ModuleNotFoundError: No module named 'forex_python'
當我嘗試構建一個貨幣轉換器 python 程序時,在其中一個開放資源的指導下,我安裝了forex-python
並確保它已安裝:
$ pip freeze
certifi==2022.12.7
charset-normalizer==2.1.1
colorgram.py==1.2.0
forex-python==1.8
idna==3.4
Pillow==9.4.0
prettytable==3.5.0
prettyTables==1.1.5
requests==2.28.1
simplejson==3.18.1
urllib3==1.26.13
wcwidth==0.2.5
然后將代碼復制/粘貼而無需進一步修改:
from forex_python.converter import CurrencyRates
c = CurrencyRates()
amount = int(input("Enter the amount: "))
from_currency = input("From Currency: ").upper()
to_currency = input("To Currency: ").upper()
print(from_currency, " To ", to_currency, amount)
result = c.convert(from_currency, to_currency, amount)
print(result)
wcwidth==0.2.5
但是模塊仍然丟失; 我什至重新安裝了 forex-python 好幾次。
Traceback (most recent call last):
File "Project002_Real-time_CurrencyConverter.py", line 1, in <module>
from forex_python.converter import CurrencyRates
ModuleNotFoundError: No module named 'forex_python'
我在谷歌上搜索過,找不到合適的解決方案,請問我遺漏了什么嗎?
更新: 07/01/2023 感謝所有評論;。 這是我的第一個問題; 我真誠地感謝所有的反饋。
mac/~~$where python
python: aliased to /usr/bin/python3
mac/~~$where python3
/Library/Frameworks/Python.framework/Versions/3.11/bin/python3
/usr/bin/python3
mac/~~$python -m pip install forex-python
我使用 PyCharm 來運行代碼,但兩個解釋器都不起作用。 相同的消息 ModuleNotFoundError。 但是我在 VS Code 上做了同樣的事情,(檢查了解釋器,檢查了 python 版本),它終於成功了。
謝謝你們!
我用導入嘗試了你的代碼,它對我有用。 好像是安裝位置的問題。
嘗試運行pip show forex-python
以獲取您的路徑( location
)。 然后運行,比如說, pip show Pillow
來獲取另一個 package 的路徑,您知道它已正確安裝並且可以導入。 比較兩條路徑並確保它們在同一位置。
如果您仍然無法使用 pip 安裝它,只需從 PyPI 下載.tar
並手動加載它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.