Python Forum

Full Version: Project structure with a virtual environment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[output]Hello to all,
Could you help me resolve the following issue: I'm having a project vscode where i created a folder containing a virtual environment and i added a python script that i'm trying to run, for reasons that i don't understand i can't run the script even after downloading the required packages in the project (after I activated the virtual environment). How should i structure the project to be able to run the script? Thank you for your help.
This how I structured the project (called trading):
1. virt (this the virtual environment folder)
2. __init__.py (an empty python file, which placed below the virt folder - not sure i should have put this file in there)
3. my_script.py (the script i'm trying to run, which placed below the __init__.py file, hence below the virt folder)
[attachment=1542]
You most see down in left corner that it run interpreter from virtual environment.
Add this to see what interpreter that is used.
import sys 

# See that use python.exe from virtual enviroment run
print(sys.executable)
Here a screenshot from a quick test.
[Image: f5kkJo.png]
See that down in left corer that it point to my test_env,you can left click and choice right environment.
When i run code see that it use python.exe from environment.

How i did make environment from command line,i use cmder and start VSCode with code .
[Image: EBh03J.png]

So if i do:
(test_env) G:\div_code\test_env
λ pip install pandas-datareader
Collecting pandas-datareader
.....
It will work from VSCode and command line.
(test_env) G:\div_code\test_env
λ python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas_datareader as pdr
>>>
>>> pdr
<module 'pandas_datareader' from 'G:\\div_code\\test_env\\lib\\site-packages\\pandas_datareader\\__init__.py'> >>> exit()
>>> exit()