简体   繁体   English

ModuleNotFoundError:没有名为“forex_python”的模块

[英]ModuleNotFoundError: No module named 'forex_python'

As I was trying to practice building a Currency Converter python program, guided by one of the open resources, I installed forex-python and ensured it was installed:当我尝试构建一个货币转换器 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

Then the code was copied/pasted without further modification:然后将代码复制/粘贴而无需进一步修改:

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

But the module was still missing;但是模块仍然丢失; I even reinstalled forex-python several times.我什至重新安装了 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'

I've searched on Google and couldn't find suitable solutions, am I missing anything here, please?我在谷歌上搜索过,找不到合适的解决方案,请问我遗漏了什么吗?

Updates: 07/01/2023 Thanks for all the comments;.更新: 07/01/2023 感谢所有评论;。 It's my first question;这是我的第一个问题; I sincerely appreciate all the feedback.我真诚地感谢所有的反馈。

  1. pip was installed under python3.11; pip安装在python3.11下; after following the suggested commands for version check, my interpreter was python 3.9;按照建议的版本检查命令后,我的解释器是 python 3.9; I have shifted it to python 3.11.我已将其转移到 python 3.11。 Just in case, I installed pip under python 3.9 too.为了以防万一,我也在 python 3.9 下安装了 pip。
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 

I used PyCharm to run the code, and neither interpreter worked.我使用 PyCharm 来运行代码,但两个解释器都不起作用。 The same message ModuleNotFoundError.相同的消息 ModuleNotFoundError。 But I did the same on VS Code, (checked interpreter, check python version), it worked finally.但是我在 VS Code 上做了同样的事情,(检查了解释器,检查了 python 版本),它终于成功了。

Thank you all!谢谢你们!

I tried your code with imports and it worked for me.我用导入尝试了你的代码,它对我有用。 It seems like an issue with the install location.好像是安装位置的问题。

Try running pip show forex-python to get your path ( location ).尝试运行pip show forex-python以获取您的路径( location )。 Then run, say, pip show Pillow to get the path of another package you know was installed correctly and you can import.然后运行,比如说, pip show Pillow来获取另一个 package 的路径,您知道它已正确安装并且可以导入。 Compare the two paths and ensure they're in the same place.比较两条路径并确保它们在同一位置。

If you're still unable install it with pip, just download the .tar from PyPI and manually load it.如果您仍然无法使用 pip 安装它,只需从 PyPI 下载.tar并手动加载它。

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

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