简体   繁体   English

模块可以在 python 中导入,但不能从命令行使用

[英]Module can be imported in python but cannot be used from command line

This is essentially the opposite of this problem: Import module works in terminal but not in IDLE这本质上与这个问题相反: 导入模块在终端中工作,但在 IDLE 中不工作

If I start a python session and try to import flask, then it works just fine.如果我启动 python session 并尝试导入 flask,那么它工作得很好。 Despite that, if I just run flask from the terminal, it is not recognized.尽管如此,如果我只是从终端运行flask ,则无法识别。

I have confirmed that the locations which pip installs to is on my system path.我已经确认pip安装到的位置在我的系统路径上。 (I'm on Windows 10 and I typed $Env:Path into Powershell to see that, for example, C:\Users\Zack\AppData\Roaming\Python\Python37\site-packages is in the system path.) (I'm on Windows 10 and I typed $Env:Path into Powershell to see that, for example, C:\Users\Zack\AppData\Roaming\Python\Python37\site-packages is in the system path.)

I am also sure that I did pip install --user flask not inside a virtual environment.我也确信我没有在虚拟环境中pip install --user flask When I run import flask; print(flask.__file__当我运行import flask; print(flask.__file__ import flask; print(flask.__file__ I see C:\Users\Zack\AppData\Roaming\Python\Python37\site-packages ) import flask; print(flask.__file__我看到C:\Users\Zack\AppData\Roaming\Python\Python37\site-packages )

Any other ideas for what could be going wrong?关于可能出现问题的任何其他想法?

Edit: I'm trying to run flask run .编辑:我正在尝试运行flask run To check the path python uses, I did (in python) import sys; for i in sys.path: print(i)要检查python使用的路径,我做了(在 python 中) import sys; for i in sys.path: print(i) import sys; for i in sys.path: print(i)

As Python language based on Python interpreter, before you use Python, it is necessarily to activate the Python env. As Python language based on Python interpreter, before you use Python, it is necessarily to activate the Python env.

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

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