ModuleNotFoundError: 找不到模块名 ‘forex_python’

huangapple go评论69阅读模式
英文:

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:

$ 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.

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!! It's my first question; I sincerely appreciate all the feedback.

  1. pip was installed under python3.11; after following the suggested commands for version check, my interpreter was python 3.9; I have shifted it to python 3.11. Just in case, I installed pip under python 3.9 too.
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. The same message ModuleNotFoundError. But I did the same on VS Code, (checked interpreter, check python version), it worked finally.

Thank you all!"

英文:

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:

$ 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(&quot;Enter the amount: &quot;))
from_currency = input(&quot;From Currency: &quot;).upper()
to_currency = input(&quot;To Currency: &quot;).upper()
print(from_currency, &quot; To &quot;, 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.

Traceback (most recent call last):
  File &quot;Project002_Real-time_CurrencyConverter.py&quot;, line 1, in &lt;module&gt;
    from forex_python.converter import CurrencyRates
ModuleNotFoundError: No module named &#39;forex_python&#39;

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!! It's my first question; I sincerely appreciate all the feedback.

  1. pip was installed under python3.11; after following the suggested commands for version check, my interpreter was python 3.9; I have shifted it to python 3.11. Just in case, I installed pip under python 3.9 too.
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. The same message ModuleNotFoundError. But I did the same on VS Code, (checked interpreter, check python version), it worked finally.

Thank you all!

答案1

得分: 0

我尝试了您的代码并且它对我有效。这似乎是安装位置的问题。

尝试运行 pip show forex-python 来获取您的路径(location)。然后运行,比如,pip show Pillow 来获取另一个您知道已经正确安装并且可以导入的包的路径。比较这两个路径,确保它们在相同的位置。

如果您仍然无法使用pip安装它,只需从PyPI下载.tar文件并手动加载它。

英文:

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). Then run, say, pip show Pillow to get the path of another package you know was installed correctly and you can import. 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.

huangapple
  • 本文由 发表于 2023年1月6日 11:04:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026547.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定