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.
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.
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.
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
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?
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.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.