Python Forum
Activate Virtual Environment and Help to get started with Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Activate Virtual Environment and Help to get started with Python
#1
Hi There,

I am  new to Python and programming.I am very interested in learning to code in particular with regards to web development using python.I have installed python 3.6 and also virtual environment(python -m Venv) in my User folder.I am trying to activate it and I am following instructions which  I found online which recommends I use the following command in the command prompt  C:\><venv>Scripts\activate.bat  but it does not work when I enter it.

I have tried to enter this using my user folder where virtual environment is installed because I can see the activate file in the scripts folder and when I do  I do not get any error message.I just get referred back to my scripts folder.I would really appreciate your help in figuring out how to activate virtual environment and how to check it has been installed.

I would also really value any advice with regards to learning python like a Professional.I am currently reading multiples books on python such as Learn Python the hard way by Fabrizio Romano and Learn Python by Mark Lutz.I apologize if this message seems mundane to my fellow members of this forum 

Thank you 

Adelton
Reply
#2
Adelton,

I am not a professional python dev however I do php professionally, as well as other non-dev things.

I also don't use Windows so I can't help much there, but I will suggest this:

* Find step-by-step tutorials which start from the installation of Python and continue on to setting up a Virtual Environment.
* I found this page here: https://virtualenv.pypa.io/en/stable/use...dows-notes which explains some notes about Windows, specifically needing win32api.
* Open the activate.bat using notepad and review the paths, there may be a path issue

It would also help if you copy/paste what is happening from your command prompt. You can click on the top right of the window (this is based on memory) and there should be something similar to "mark" or "select" which will allow you to copy the info into your buffer, then you can paste here using the proper code bbcode tags.

If you take us step-by-step what you are doing you are more likely to get some help.

Best of luck
Reply
#3
Quote:* Find step-by-step tutorials which start from the installation of Python and continue on to setting up a Virtual Environment.
* I found this page here: https://virtualenv.pypa.io/en/stable/use...dows-notes which explains some notes about Windows, specifically needing win32api.
* Open the activate.bat using notepad and review the paths, there may be a path issue
In 3.6 virtual environment is build in,
no need for win32api or install the 3-party virtualenv that you link to.

Here is a run with explanation.
I use cmder it work the same in cmd(but which python don't work).
You are right in Windows you give path to activate.bat,in Linux there is a own command source venv/bin/activate
C:\
# Make virtual enviroment
# Python 3.6 is set in Environment Variables Path(3.6 dos this for you under installtion)
λ python -m venv my_env

# cd into the folder
C:\
λ cd my_env

# Now activate bye given path to bat file
C:\my_env
λ C:\my_env\Scripts\activate.bat

# Now is folder active,you see (my_env)
(my_env) C:\my_env

# With cmder i can check that right python is used
λ which python
/c/my_env/Scripts/python

# Test install into virtual environment 
(my_env) C:\my_env
λ pip install requests
Collecting requests
 Downloading requests-2.13.0-py2.py3-none-any.whl (584kB)
   100% |████████████████████████████████| 593kB 1.4MB/s
Installing collected packages: requests
Successfully installed requests-2.13.0

# Load Python and check Requests
(my_env) C:\my_env
λ python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.13.0'
>>> exit()

# Freeze version info
(my_env) C:\my_env
λ  pip freeze > requirements.txt

# Read requirements.txt
(my_env) C:\my_env
λ more requirements.txt
requests==2.13.0
Reply
#4
I would like to thank you both for your insightful solutions to resolving this mundane problem because I have managed to activate the activate.bat file in the command line.
Reply
#5
Quote:Snippsat wrote:
I use cmder it work the same in cmd(but which python don't work).

When Snippsat mentioned cmder to me, I installed it immediately.
I will vouch for the app. I don't even think about Windows 'cmd' anymore, I automatically
right click and use cmder.

Now I use grep in windows the same as I would on Linux.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 218 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Best practice on using virtual environments in Python bytecrunch 6 796 Feb-14-2024, 03:22 PM
Last Post: snippsat
  Virtual Env changing mysql connection string in python Fredesetes 0 370 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Installing python packages in a virtual environment Led_Zeppelin 1 757 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,255 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,608 May-04-2023, 07:24 PM
Last Post: snippsat
  Problem with virtual environment standenman 2 1,005 Feb-23-2023, 07:09 PM
Last Post: standenman
  Cannot get started standenman 4 1,204 Feb-22-2023, 05:25 PM
Last Post: standenman
Question Virtual Environment (using VS Code) Ashcora 4 13,629 Feb-15-2023, 07:17 PM
Last Post: snippsat
  Python Scripting Environment jpotter0 1 1,709 Nov-19-2022, 03:07 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