Git Product home page Git Product logo

Comments (8)

gianchub avatar gianchub commented on August 14, 2024

Hi @justingdbyrne,
from the path to the Python executable in your error, it seems you're already using an executable from a virtual environment. I might be wrong though. If that is not the case, I would try and see if you have permission to create files and folders.
You also seem to already have the Ch2.venv folder already, so you might want to make sure you delete that, or choose another name for your venv.
Another suggestion I would have is not to create venv folders within a repo, it might be better to have a separate folder you use to experiment.
Finally, please remember the book is in Python3.9, not 3.10, so if you follow instructions and you get different results, it is possible (though, quite unlikely for this particular scenario) that the different version might be the reason.
HTH,
fab

from learn-python-programming-third-edition.

justingdbyrne avatar justingdbyrne commented on August 14, 2024

@gianchub,
The path in the error is from the directory created during the execution of the venv command. I delete this each time before executing the command again with the same end results so I don't think that is it. Changing the name of the venv doesn't help.

I'm not sure what a reop is, sorry. I am also troubleshooting the issue here:
https://www.reddit.com/r/learnpython/comments/u13l1p/virtual_environment_with_venv_work_but_only_in/

I've tried a fresh install of Python. I'm struggling to progress in the book because of this. It seems like the ability to create virtual environments is pretty central to clean code, so I could do with a little help.

from learn-python-programming-third-edition.

justingdbyrne avatar justingdbyrne commented on August 14, 2024

I have had some success resolving it. I can create virtual environments in the subdirectories of the chapter folder, but not in the chapter 2 folder itself. Could you think of why that might be and if it would be an issue to completing the work? I don't know if that would be a problem, but I can see it being difficult to make use of the files on git hub if the virtual environment must be stored in a different directory. Does that defeat the purpose of having a specific chapter venv?

from learn-python-programming-third-edition.

justingdbyrne avatar justingdbyrne commented on August 14, 2024

Further trouble shooting: Creating the venv in the directory works for chapter 2, but not if the python scripts "enum.py" or "numbers.py" are in the directory at the time of creation.

The first leads to the following error:

Error: Command '['C:\Users\my_name\Documents\LearnPython\ch.02\.venv\Scripts\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

and the second to this error:

C:\Users\my_name\Documents\LearnPython\ch.02>python -m venv .venv
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\runpy.py", line 187, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "C:\Program Files\Python310\lib\runpy.py", line 146, in _get_module_details
return get_module_details(pkg_main_name, error)
File "C:\Program Files\Python310\lib\runpy.py", line 110, in get_module_details
import(pkg_name)
File "C:\Program Files\Python310\lib\venv_init
.py", line 7, in
import logging
File "C:\Program Files\Python310\lib\logging_init
.py", line 26, in
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Program Files\Python310\lib\re.py", line 124, in
import enum
File "C:\Users\my_name\Documents\LearnPython\ch.02\enum.py", line 1
>>> GREEN = 1
^^
SyntaxError: invalid syntax

So perhaps naming the scripts that is causing some issues with python.... Renaming the files by appending the characters "script" (e.g. enumscript.py, or numbersscript.py fixes the issue in this case.

from learn-python-programming-third-edition.

gianchub avatar gianchub commented on August 14, 2024

@justingdbyrne
I wrote repo, not reop ;)
You normally don't put your virtual environment folder within the code, (within the repository folder, where the source code lives).
You should probably checkout virtualenv and virtualenvwrapper, where you'll find plenty of info (and debug info) on virtual environments.
So, to answer your question, no, it does not defeat having a venv per chapter. The point of that is to keep dependencies as short and simple as possible and make it easier for people to experiment.

I don't use windows, so debugging this issue further is an adventure I cannot accompany you on. I would recommend googling your errors, and see if you can find anyone who had something similar on stackoverflow or any other website that host info about venvs.

I would recommend you to create the venv in a project folder, not where the source code is, and then you activate it and change into the chapter folders to run the code there. You would realise this is exactly what happens when you use virtualenvwrapper, which creates all the virtualenvs under a folder (like ~/.virtualenvs) for you.

As this is not an issue related to the book or the code in the book, I'm closing this thread now, wish you all the best with your issue and hope you get to the bottom of it quickly.

Regards,
fab

from learn-python-programming-third-edition.

justingdbyrne avatar justingdbyrne commented on August 14, 2024

I agree that I think that I can move forward now, as long as I rename the files. However, this is how I read the instructions on the Git and in the book. So I respectfully disagree that "this is not an issue related to the book or the code in the book".

In the read_me you write:

"Let's now pretend you want to work on Chapter 12. First, change into the folder for Chapter 12 (it's called ch12):

"$ cd ch12

"Then, create a virtual environment. In this example the virtual environment will live inside the chapter's folder, but you can choose any other folder that might suit you better.

"$ python3.9 -m venv .venv"

That's what I tried to do and I got this error. I guess it could be made clearer that this is not supposed to be working with the chapter folders you download from Git.

Looking at this from a constructive point of view, I'm trying to say that this section of the instructions was unclear to me - someone who has worked in R for many years and who has a little experience already with BASH. I'm no genius, but I can troubleshoot issues and this one stumped me for a long time until I devoted the morning to solving it.

I believe it could also confuse other Windows users too, especially if they have less experience. As this section comes right at the start of the book it could be dissuading for readers who feel like they can't get over the first hurdle with this "python-thing" and give up! Especially as the Stack overflow responses for this error are not helpful.

I would suggest adding some section to the read_me about this or even modifying the file name from "enum.py" and "numbers.py" to something else as they appear to be the root cause of the issue in the end. Take it or leave it, but that seems like constructive advice to me.

from learn-python-programming-third-edition.

gianchub avatar gianchub commented on August 14, 2024

@justingdbyrne thank you for the feedback.

from learn-python-programming-third-edition.

gianchub avatar gianchub commented on August 14, 2024

@justingdbyrne I have updated the README.md file, adding a note. I hope now it's clearer.
BTW, I was following the example I gave, and in ch12 the procedure as it was, succeeds. This confused me, until I realised you were on ch02. I thought, since you were using a different OS, a different python version, and a different venv name, that the issue might be on your system for some reason (it happens a lot believe me).
Anyway, thank you again for the feedback, hope now it's sorted and hope you enjoy the rest of the book.
Regards,
fab

from learn-python-programming-third-edition.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.