简体   繁体   English

使用pip安装了Python软件包,但无法导入使用

[英]Installed Python Package with pip, but cannot import for use

Apologies if this is the noobest question in existence, but I think this is an issue with my path? 抱歉,如果这是现有的最棘手的问题,但我认为这是我的问题吗? Terminal output below 终端输出如下

Vincents-MacBook-Pro:~ vincentlevinger$ pip install binance
Requirement already satisfied: binance in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Vincents-MacBook-Pro:~ vincentlevinger$ python import binance
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'import': [Errno 2] No such file or directory
Vincents-MacBook-Pro:~ vincentlevinger$ 

This is not Python: 这不是Python:

python import binance

Here, you are trying to invoke the Python interpreter with the python command. 在这里,您尝试使用python命令调用Python解释器。 But this command does not take Python code as argument, it takes an executable! 但是此命令不会将Python代码作为参数,而是需要一个可执行文件! So you are actually trying to run the import script, which of course, doesn't exist. 因此,您实际上是在尝试运行import脚本,这当然是不存在的。

If you want to access the Python interpreter without feeding him a script, just run the python command without arguments: 如果要访问Python解释器而不给他脚本,请运行不带参数的python命令:

python

It will open the Python interpreter (you can recognise it by its prompt: >>> ). 这将打开Python解释器(您可以通过它迅速认出它: >>> )。 Now you can type Python code: 现在您可以输入Python代码:

>>> import binance

To run a Python code from the command line use this syntax: 要从命令行运行Python代码,请使用以下语法:

python -c "import binance"

Option -c accept a string (one string, hence the quotes that combine space-separated words into one parameter) that will be interpreted by python. 选项-c接受将由python解释的字符串(一个字符串,因此将用空格分隔的单词组合成一个参数的引号)。 You can even pass a multiline script: 您甚至可以传递多行脚本:

python -c "
import binance
print(binance.prices())
"

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

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