Pipenv issue

I am currently completing the Learn Python: pipenv task in the computer science course and am running into issues.

I followed the tutorial intently, so I am sure I haven’t made mistakes. However, at the 20:30 mark in the video tutorial is where things go wrong.

After I have used pipenv shell command to work in the virtual environment, if I load the python interpreter using python3, I can’t do any further steps without running into errors. However, if I type python to enter the interpreter, everything runs fine, and I can follow the tutorial.

I want to know why this happens and if I have not done something right on my end.

I am using VSCode with gitbash if that is helpful.

Hi there,

What operating system are you using, Windows or mac?

I am using Windows.

To add on, I realised that the virtual environment required python3.11.0 and resolved my issue somewhat.

I say somewhat because I am still unaware of why this happens.

Using python --version it returns Python 3.11.0 (the version required in my venv)
Using python3 --version it returns Python 3.10.8

Which explains why I don’t run into any issues when using python to enter the python interpreter.

So I guess my new question is, what’s the difference between python and python3 when entering the python interpreter? How do I control which versions they choose?

Also, this is my first time using the forums, so excuse my ignorance if you are not supposed to ask new questions within questions.

Hey ,

I work with pipenv on a daily basis, I feel confident I can help you with this issue.

I realised that the virtual environment required python3.11.0

No, technically, pipenv requires 3.8 or greater.

Question: what’s the difference between python and python3 when entering the python interpreter?

The Python3 command was introduced because the python command pointed to python2. Since then, Python3 has become the default and thus python points to python3 on most but not all systems. So in other words, if you just have Python 3 + on your machine, and not Python 2, you can use Python , if you have both you will use Python3, Does this makes sense?

Specifying Versions of Python

How do I control which versions they choose?

By default, Pipenv will initialize a project using whatever version of python the system has as default. To create a new virtualenv, using a specific version of Python you have installed (and on your PATH), use the --python VERSION flag, like so:
Use Python 3:

pipenv --python 3

Use Python3.6:

pipenv --python 3.6

Use Python 2.7.14:

pipenv --python 2.7.14

When given a Python version, like this, Pipenv will automatically scan your system for a Python that matches that given version.

Please note: To do this, the specific version of Python you want to use must be installed, and on your PATH!

Specifying Versions of a Package

Likewise, you can specify versions of packages as well. For example, to install requests you can use:

pipenv install requests~=1.2

This will update your Pipfile to reflect this requirement, automatically.

Example of Pipenv Workflow

These are the steps to follow when working with pipenv:

  1. Install from Pipfile, if there is one:
pipenv install

Or, add a package to your new project

 pipenv install <package>

This will create a Pipfile if one doesn’t exist. If one does exist, it will automatically be edited with the new package you provided.

  1. Next, activate the Pipenv shell
pipenv shell

To run a python script in pipenv :

python <filename.py>

Also, this is my first time using the forums, so excuse my ignorance if you are not supposed to ask new questions within questions

My friend, please feel free to ask any question you like ~ this is how we learn! Let me know if my explanation answered your questions. If you need further assistance with anything, please let me know!

Best regards,

1 Like

Python 2 is deprecated. Use python3.

Wow, yes, you answered my questions and more.

With specifying versions of Python with pepenv --python x, in the tutorial the teacher used pipenv --three, is this the same as pipenv --python 3?