How to set path for streamlit in virtual conda environment

I have a Conda virtual environment. installed Python, pandas, numpy and streamlit.

I have streamlit working fine (took me a while…).

to run a script that is for sure in my virtual environment and within the streamlit folder I have to type:

streamlit run C:\Users\Gebruiker\Anaconda3\envs\test3\Lib\site-packages\streamlit\test\streamtest3.py

As you can see the file is within te virt env etc.

Question: is there a way to seth the path in streamlit (from conda) so that running a file, for example, can be done with:

‘’’

streamlit run streamtest3.py

‘’’

Thanks ! greetings JanAsk the community or our support engineers for answers to questions.

Hello @Janneman !

I’m not sure I understood your issue, so I’m answering to what I understood of your issue and then will let you correct me ! You want streamlit to be available to run a script from anywhere on your computer.

Since you’re running Anaconda on Windows, I assume you followed the same steps as Streamlit’s Installing in a conda environment guide (don’t hesitate to drop and recreate an environment from scratch, Conda is good for this).
Which means Streamlit is installed inside a conda environment with numpy, pandas etc…and when you put a script inside the conda folder, it’s true it will use the Python executable and streamlit installed in this folder.

If you want to run Streamlit on a file anyway on your computer, you can activate the conda environment in your terminal so that it will use streamlit and python in this folder :

  • follow the procedure in the Wiki to open a terminal from the Anaconda navigator, with the Conda environment where Streamlit is installed. In this new terminal, streamlit should be accessible, then you can browse to the folder with your script through a cd command and run streamlit run app.py
  • in any Anaconda prompt (you can open one from the Start menu), activate your conda environment with conda activate <streamlit_environment>. Your prompt should then have the name of the environment preprended like (streamlit_environment) >, which means python and streamlit will be run from the conda folder. Then streamlit run app.py should run correctly too.

Ping us if you have any issues on my description :wink:
Fanilo

1 Like

Hey Fanilo! Wow, many thanks!! this works, exactly what I was looking for.
Many thanks again, greetings Jan
ps: so what I didn’t understood was the part of having to change directory from within the virt env.

2 Likes