Python Forum

Full Version: Setting up virtual environment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to setup a virtual environment. I don't see anything when I run this code. No folders are created. I just don't know if there should be something.

def create(self, env_dir):
    """
    Create a virtualized Python environment in a directory.
    env_dir is the target directory to create an environment in.
    """
    env_dir = os.path.abspath(env_dir)
    context = self.ensure_directories(env_dir)
    self.create_configuration(context)
    self.setup_python(context)
    self.setup_scripts(context)
    self.post_setup(context)
As always, I appreciate your help!
You are way of as usual Wink
It's because of you error message in your first post in this Thread.
I asked if the same error(It's just Warning) happens in a virtual environment.
I think code is what @Larz60+ help you with in a mega Thread?

When i say test in a virtual environment,i mean make a environment the install Requests and BeautifulSoup.
So it don't interfere way OS has installed.

Eg all is done from command line(cmd).
# Make environment 
E:\div_code>python -m venv my_env

# Cd in 
E:\div_code>cd my_env

# Activate
E:\div_code\my_env>E:\div_code\my_env\Scripts\Activate

# Check pip see that use environment
(my_env) E:\div_code\my_env>pip -V
pip 10.0.1 from e:\div_code\my_env\lib\site-packages\pip (python 3.7)

# Install
(my_env) E:\div_code\my_env>pip install beautifulsoup4 requests lxml
......

(my_env) E:\div_code\my_env>
Then you place your script in my_env folder and run with environment Activate python my_code.py.
Yes - you are correct. I would have stayed with that one but it seems when I post things he's helped / done for me - all I get is silence. I truly want to learn this!

I will try this! Thank you!
Ok - I have my new virtual environment setup. How do I setup my Python project? Is there a special way to run it? I simply copied my folder into my new virtualenv folder. I'm still getting the same errors.

Forgive me - I should have read ALL of the directions.
Alright - that part is covered. Where do I run this? I've tried a DOS command and a Python Shell. Both gave me pretty typical errors (I've seen them many many times).

I'm reading the manual so maybe I haven't gotten to that part yet.

Any ideas?

Thanks again!
Ok - I'm on page 16 of the 'Python Packaging User Guide'. I used DOS to do the command 'pip install --user pipenv'. It seemed to run OK as in I had no errors but I didn't see anything either. The thing is - that's not where my Python project is installed nor is it where my Python installation is. So I did the same to both of them. I also set the PATH to the location that is suggested for Windows. I found the path page 16 suggests so installed 'pipenv' to my project location "C:\WOGCC_Downloads" and my Python installation path "C:\Python365".

When I try to use the 'pipenv' is says "'pipenv' is not recognized as an internal or external command, operable program or batch file".

Can you tell me what I need to do to proceed beyond this point?

Again - as always - thank you for your help!
Why are you messing with pipenv?
it's okay but all you need to test code in virtual environment is in my post with venv that's build into Python.

If i want to test this code isolatet in virtual environment that i made in my previous post.
# web_title
from bs4 import BeautifulSoup
import requests

url = 'https://www.python.org/'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'lxml')
print(soup.select('head > title')[0].text)
I save web_title.py in my_env and Activate.
From cmd:
# Activate
E:\div_code\my_env>E:\div_code\my_env\Scripts\Activate

# Now environment is active see (my_env)
# Run code
(my_env) E:\div_code\my_env>python web_title.py
Welcome to Python.org

(my_env) E:\div_code\my_env>
tjnichols Wrote:I truly want to learn this!
Then don't start with a big web-scraping project that look more like job descrtion,
and have @Larz60+ writing all code for you.
Web-Scraping part-1
Ok - I'm working on my own version. I've completed my 'rush' project so this is a perfect time to do it. Currently, I'm simply working on a wish list!

Thank you for your support!