Streamlit does not use venv

Hey everyone,

I am having trouble to make Streamlit use my virtual environment, it insists on using the global environment.
Here is my list of processes:

  • Create a new folder.
  • Open the folder using vscode.
  • python -m venv env
  • Activate the env
  • Install packages such as streamlit and additional package called pyeq3. (Note that pyeq3 is not installed in my global package, but others are.)
  • In the terminal of vscode where env is already activated, write “streamlit run mycode.py”.
  • Streamlit says pyeq3 is not installed and the error message refers to script_runner.py that is located inside my global environment. So it does not look into my virtual environment.

Can anyone see what I am doing wrong here?

1 Like

Hi @Berk_Demir -

I use conda instead of venv, but I’ve had issues like this before. One thing that can be messy about VSCode is that the editor can be in one environment, but the terminal is pointing to another:

Here, the VSCode editor is pointing to attractors, and the terminal is pointed to metricsdash. So depending on where you are trying to point to, you can get weird things happening.

Best,
Randy

In your case, I would expect metricdash to start streamlit. However, that’s not working for me.

You can see that my VSCode uses same environment both in terminal and VSCode. However, even though this venv has the pyeq3 module I use, streamlit cannot find it.

@Marc, based on your perfect awesome-streamlit guideline for VSCode, would you help the case?

Hi @Berk_Demir!
I’m running into the same issue. Could you resolve it?

You never know exactly in which environment the VSCode Terminal runs…
IMHO, just use your standard terminal and not the built-in terminal of VSCode.

1 Like

to support your impression that you never know in which env the VSCode terminal runs: I restarted VSCode, activated the venv again and it worked without me changing anything :smiley:

So frustrating but I’m having the same issue. Streamlit uses one python executable (pyenv) while vscode and my terminal outside of vscode use another (venv). Did you ever find a solution?

Hi!

Had the same issue. Found a solution following the following tuto: Installing in a virtual environment · streamlit/streamlit Wiki · GitHub

I don’t know if this helps other folks, but I just found “weirdness” with my Streamlit app being able to find certain packages. I tracked that down to the streamlit command in my path essentially ignoring the python environment I’m working in and directly using a python 3.11 which is not the environment I’m managing.

First line in that streamlit is:
#!/opt/homebrew/opt/python@3.11/bin/python3.11

I have never seen this before having managed many streamlit environments, but maybe something in my environment is now messed up between streamlit, my path etc… I don’t know if this is what is causing other folks’ issues but worth checking if you do bump into this.

Al

p.s. - I did not go further into digging into what happened here. I just created a copy of the streamlit script in my working directory and changed it to use the correct python.