Python Forum
Creating Python scripts in Visual Studio Code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Python scripts in Visual Studio Code
#1
Hi,
I am new to Python programming. I have developed some scripts that read data from ms access database and post the results to firebase firestore database . So far i have created just 3 scripts in Visual Studio Code (without creating any Virtual Environment) and they all run perfectly. My first question is , is it ok to run python scripts without creating a virtual environment ? If No how do i create a virtual environment inside Visual Studio Code? My second question is how can i integrate my frontend html with python on button click ?

Please help

Thanks & regards

Sanjish
Reply
#2
You can run python scripts without a virtual environment, but it keeps code having to do with the project isolated, so that you don't have to carry baggage from non related projects.

Virtual environment is made on command line (terminal emulator window), usually from outside of VSCode, but would work from a terminal window inside of VSCode as well.

The python command is python -m venv myvirtualenvname I usually name the virtual environment venv as well, which avoids confusion so then command python -m venv venv.

Once created, you must tell VSCode where the interpreter is located, from a code, do this by typing ctrl-shift-P in VSCode. in the window, type: Python: Select Interpreter
Scroll down until you find an entry with: .venv/bin/python. Your virtual environment will be activated when you run a script.
Reply
#3
As mention over make virtual environment from command line.
I always use code . to start VS Code from virtual environment folder or any other folder that want start as root in VS Code.
Then left click down in left cornier or Python: Select Interpreter(ctrl-shift-P),then choose Interpreter of virtual environment or which Interpreter that want to use.
VS Code from start
Quick demo.
# Make virtual environment
G:\div_code
λ python -m venv my_env

# Cd in
G:\div_code
λ cd my_env\

# Activate
G:\div_code\my_env
λ G:\div_code\my_env\Scripts\activate

# Start VS Code
(my_env) G:\div_code\my_env
λ code .
[Image: uAzCsO.png]
Reply
#4
Hi ,
Thanks for the info on Virtual Environment. Could you please also help me in Linking html to Python page ?
Reply
#5
(Dec-21-2020, 11:09 AM)Sanjish Wrote: My second question is how can i integrate my frontend html with python on button click ?
Thanks for the info on Virtual Environment. Could you please also help me in Linking html to Python page ?
You will need something like eg Flask or Django.
In the old days there was CGI(which now dead in Python),so eg Flask has taken over that role in a more modern and better way using WSGI underneath.
Look at this post for a basic setup with html and css.
There is also webbrowser module,that can be used for displaying html,but has no connection back to Python with eg a button click.
Sanjish likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  embedded Python scripts - is it worthwhile Skaperen 3 686 Feb-21-2024, 01:25 AM
Last Post: Skaperen
  Visual Studio for Python 357mag 3 65,365 Jul-11-2023, 08:15 AM
Last Post: PyDan
  images and pixels in typical Python scripts Skaperen 0 1,244 Oct-14-2021, 12:29 AM
Last Post: Skaperen
  visual studio code python how to get source code of import module definitian umen 2 3,957 Jun-13-2020, 06:20 PM
Last Post: umen
  Visual studio shortcut key to add comments to python code mp3909 15 9,429 Jun-06-2020, 01:15 PM
Last Post: mp3909
  suid scripts in python? Skaperen 0 2,159 Sep-29-2019, 10:28 PM
Last Post: Skaperen
  Python Shell As Preferred Mode For Integrated Terminal In Visual Studio Code adt 4 4,060 Sep-07-2019, 06:00 PM
Last Post: adt
  Can copyright be applied python scripts? tim777 3 4,893 Sep-04-2019, 12:20 PM
Last Post: DeaD_EyE
  Finding Scripts for Python Johnny1998 1 2,211 Jul-31-2019, 08:07 PM
Last Post: Yoriz
  Visual studio and Afzal 0 1,781 Feb-20-2019, 11:10 AM
Last Post: Afzal

Forum Jump:

User Panel Messages

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