简体   繁体   中英

How to effectively get python modules working across different environments

I'm a newbie to python and just trying to get my head wrapped around how to get things to run/work in python across different environments. What I mean in this context in regards to environment is this. I'm learning python on my MacBook pro - Catalina 10.15.5. I've installed python using brew install . I use pyenv to control versions. Through iTerm I would create virtual environments using virtualenv and pip install to install modules, etc.

I'm also using Visual Studio Code and PyCharm to learn and understand these tools as well.

I've reviewed and tried a number of python tutorials in my journey to learning python. With that said, why is it when using iTerm , if I do a pip install <module> , the module shows being installed with no errors, but when running the application ( FLASK_APP=app.py flask run) , i'll get this message:

Traceback (most recent call last):
  File "/Users/pynoob/.pyenv/versions/3.8.0/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/Users/pynoob/Desktop/MyWork/Learn/LearningPython/OktaTutorial/app.py", line 2, in <module>
    from flask_oidc import OpenIDConnect
ModuleNotFoundError: No module named 'flask_oidc'

However, when I run these same in Visual Studio Code, in the terminal, it works. How? What am I misunderstanding fundamentally when using modules? Does it have to do with iTerm vs. Visual Studio Code?

Here's the snippet of python code:

from flask import Flask, render_template, g, redirect, url_for
from flask_oidc import OpenIDConnect
from okta import UsersClient

After reviewing the article as shared in the comment here . I ran the following commands in iTerm and got it working:

 python3 -m venv <nameyourenv>
 pip install -r requirements.txt
 FLASK_APP=app.py flask run

Example output:

 * Serving Flask app "app.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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