Python Forum
Project structure with a virtual environment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Project structure with a virtual environment
#1
[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)
   
Reply
#2
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 238 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Installing python packages in a virtual environment Led_Zeppelin 1 763 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Problem with virtual environment standenman 2 1,007 Feb-23-2023, 07:09 PM
Last Post: standenman
Question Virtual Environment (using VS Code) Ashcora 4 13,907 Feb-15-2023, 07:17 PM
Last Post: snippsat
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,374 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Virtual environment path? Led_Zeppelin 1 2,304 Jul-22-2021, 01:40 PM
Last Post: snippsat
  virtual environment heye 4 2,462 Jul-04-2021, 06:47 AM
Last Post: ndc85430
  import statement in a virtual environment leodavinci1990 1 2,357 Mar-04-2021, 12:57 AM
Last Post: snippsat
  Virtual environment and upgrading python 3.5 to 3.9 NeilUK 4 12,141 Jan-24-2021, 01:02 PM
Last Post: snippsat
  Not able to set up a virtual environment with venv mohanp06 7 13,799 Oct-27-2020, 12:18 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020