Skip to content

Latest commit

Β 

History

History
709 lines (529 loc) Β· 14.5 KB

z_PYENV_installing.md

File metadata and controls

709 lines (529 loc) Β· 14.5 KB

🟑 PYENV installing


  • ⚠️ check also the issues you can possibly have in different python versions python-toavoid


🧢Why? 🧢 🧢

I encountered an issue when trying to run the code on the weather api exercise


the issue:

  • red underline due to packages not being installed in the environment

  • later on i will discover that not only this type of red underline appears because the packages are not well installed but also because even if the packages are installed, πŸ”΄ the Pylint will recognize other type of issues (so here the pylint is not the bad guy but the good one, its only telling you that something is wrong Pylint-errs so its a good thing to have it.


  • ⚠️ check also the issues you can possibly have in different python versions python-toavoid
import requests
from dotenv import load_dotenv
#
import os

Somehow i always ended up having the red underline on the Weather.py


  • So i checked the requirements.txt of the project, and when I hovered under the dotenv (you will see 3 dots ) and the charset, I could see the below:
Package `charset-normalizer` is not installed in the selected environment.Python-InstalledPackagesCheckernot-installed
//
//
Package `python-dotenv` is not installed in the selected environment.Python-InstalledPackagesCheckernot-installed

🌈 solution





🟣 PYENV installation



🟑 Check this video to see how you will be able to change the versions min: 5:40 / Manage Multiple Python Versions with PyEnv


PYENV is a great tool for managing multiple Python versions on your system, regardless of the system's default Python installation or available packages.

How to Install and Run Multiple Python Versions on Ubuntu/Debian | pyenv & virtualenv Setup Tutorial

Here's a step-by-step guide to installing pyenv and setting it up to manage Python versions and virtual environments:


🟠 install

This command below installs pyenv βœ‹ globally on your system. It sets up pyenv in your home directory (~/.pyenv) and modifies your shell's initialization file (like .bashrc, .zshrc, etc.) to include pyenv commands.

curl https://pyenv.run | bash

output

$ sudo curl https://pyenv.run | bash
[sudo] password for mycomputer:
sudo: curl: command not found

🟠 update it

sudo apt update
// you will have a long list of updated packages


🟠 try again to install curl

sudo apt install curl

output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  curl
0 upgraded, 1 newly installed, 0 to remove and 3 not upgraded.
Need to get 227 kB of archives.
After this operation, 532 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 curl amd64 8.5.0-2ubuntu10.1 [227 kB]
Fetched 227 kB in 1s (207 kB/s)
Selecting previously unselected package curl.
(Reading database ... 229525 files and directories currently installed.)
Preparing to unpack .../curl_8.5.0-2ubuntu10.1_amd64.deb ...
Unpacking curl (8.5.0-2ubuntu10.1) ...
Setting up curl (8.5.0-2ubuntu10.1) ...
Processing triggers for man-db (2.12.0-4build2) ...

🟠 try to install pyenv again

sudo curl https://pyenv.run | bash

output

```javascript
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   270  100   270    0     0    198      0  0:00:01  0:00:01 --:--:--   198
Cloning into '/home/mycomputer/.pyenv'...
remote: Enumerating objects: 1267, done.
remote: Counting objects: 100% (1267/1267), done.
remote: Compressing objects: 100% (698/698), done.
remote: Total 1267 (delta 747), reused 723 (delta 436), pack-reused 0
Receiving objects: 100% (1267/1267), 627.16 KiB | 965.00 KiB/s, done.
Resolving deltas: 100% (747/747), done.
Cloning into '/home/mycomputer/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), 38.72 KiB | 388.00 KiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into '/home/mycomputer/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
Receiving objects: 100% (10/10), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0
Resolving deltas: 100% (1/1), done.
Cloning into '/home/mycomputer/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (56/56), done.
remote: Total 64 (delta 10), reused 29 (delta 1), pack-reused 0
Receiving objects: 100% (64/64), 42.50 KiB | 414.00 KiB/s, done.
Resolving deltas: 100% (10/10), done.

WARNING: seems you still have not added 'pyenv' to the load path.

# Load pyenv automatically by appending
# the following to
# ~/.bash_profile if it exists, otherwise ~/.profile (for login shells)
# and ~/.bashrc (for interactive shells) :

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# Restart your shell for the changes to take effect.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"

🟠 edit the initialization

// 1
sudo apt-get update

//2
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \
libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl git

🟣 nano

  • this will open the nano
nano ~/.bashrc


# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

🟧 to save: strg + O, check the file you are saving on (be careful), if its correct press ENTER, then.. to get out press strg + X


🟠 Applying Changes


  • After adding the lines to your initialization script, save the file and close the text editor.

  • To apply these changes, you typically need to reload the shell or source the initialization script:

source ~/.bashrc


🟒 Verify Installation

To verify that pyenv is installed correctly, you can check its version:

pyenv --version

output

pyenv 2.4.7






🟑 check the list of Python versions



The pyenv install --list command is used to list all the versions of Python that can be installed using pyenv, a popular tool for managing multiple Python versions on a single system.

pyenv install --list

Here's a breakdown of its purpose:

Listing Available Python Versions: When you run pyenv install --list, pyenv fetches and displays a list of all available Python versions that it supports. This list includes both stable releases and pre-release versions.

Version Selection: This command helps you decide which specific version of Python you want to install. It provides information such as version numbers and release dates, which can be useful for making an informed choice.

Managing Python Environments: πŸ”΄ pyenv allows you to install multiple versions of Python on your machine and easily switch between them. By listing available versions, you can see which ones are compatible with your applications or projects.


🌈 check this before you choose a version

  • Python release cycle (end of life)

https://devguide.python.org/versions/

βœ‹(this is just a short list, you have a lot more, but from here i will pick the versions i want to test, so to see if i have the same red underline issue when trying to import the DOTENV)

Available versions:
  2.1.3
  2.2.3
  2.3.7
  2.4.0
  2.4.1
  2.4.2
  2.4.3
  2.4.4
  2.4.5
  2.4.6
  2.5.0
  2.5.1
  2.5.2
  2.5.3
  2.5.4
  2.5.5
  2.5.6
  2.6.0
  2.6.1
  2.6.2
  2.6.3
  2.6.4
  2.6.5
  2.6.6
  2.6.7
  2.6.8
  2.6.9
  2.7.0
  2.7-dev
  2.7.1
  2.7.2
  2.7.3
  2.7.4
  2.7.5
  2.7.6
  2.7.7
  2.7.8
  2.7.9
  2.7.10
  2.7.11
  2.7.12
  2.7.13
  2.7.14
  2.7.15
  2.7.16
  2.7.17
  2.7.18
  3.0.1
  3.1.0
  3.1.1
  3.1.2
  3.1.3
  3.1.4
  3.1.5
  3.2.0
  3.2.1
  3.2.2
  3.2.3
  3.2.4
  3.2.5
  3.2.6
  3.3.0
  3.3.1
  3.3.2
  3.3.3
  3.3.4
  3.3.5
  3.3.6
  3.3.7
  3.4.0
  3.4-dev
  3.4.1
  3.4.2
  3.4.3
  3.4.4
  3.4.5
  3.4.6
  3.4.7
  3.4.8
  3.4.9
  3.4.10
  3.5.0
  3.5-dev
  3.5.1
  3.5.2
  3.5.3
  3.5.4
  3.5.5
  3.5.6
  3.5.7
  3.5.8
  3.5.9
  3.5.10
  3.6.0
  3.6-dev
  3.6.1
  3.6.2
  3.6.3
  3.6.4
  3.6.5
  3.6.6
  3.6.7
  3.6.8
  3.6.9
  3.6.10
  3.6.11
  3.6.12
  3.6.13
  3.6.14
  3.6.15
  3.7.0
  3.7-dev
  3.7.1
  3.7.2
  3.7.3
  3.7.4
  3.7.5
  3.7.6
  3.7.7
  3.7.8
  3.7.9
  3.7.10
  3.7.11
  3.7.12
  3.7.13
  3.7.14
  3.7.15
  3.7.16
  3.7.17
  3.8.0
  3.8-dev
  3.8.1
  3.8.2
  3.8.3
  3.8.4
  3.8.5
  3.8.6
  3.8.7
  3.8.8
  3.8.9
  3.8.10
  3.8.11
  3.8.12
  3.8.13
  3.8.14
  3.8.15
  3.8.16
  3.8.17
  3.8.18
  3.8.19
  3.9.0
  3.9-dev
  3.9.1
  3.9.2
  3.9.4
  3.9.5
  3.9.6
  3.9.7
  3.9.8
  3.9.9
  3.9.10
  3.9.11
  3.9.12
  3.9.13
  3.9.14
  3.9.15
  3.9.16
  3.9.17
  3.9.18
  3.9.19
  3.10.0
  3.10-dev
  3.10.1
  3.10.2
  3.10.3
  3.10.4
  3.10.5
  3.10.6
  3.10.7
  3.10.8
  3.10.9
  3.10.10
  3.10.11
  3.10.12
  3.10.13
  3.10.14
  3.11.0
  3.11-dev
  3.11.1
  3.11.2
  3.11.3
  3.11.4
  3.11.5
  3.11.6
  3.11.7
  3.11.8
  3.11.9
  3.12.0
  3.12-dev
  3.12.1
  3.12.2
  3.12.3
  3.12.4
  3.13.0b3
  3.13.0b3t
  3.13-dev
  3.13t-dev
  3.14-dev
  3.14t-dev

🟒 i will choose this:

pyenv install 3.8.18

🟠 Once you type this command pyenv install 3.8.18 you will have to βœ‹ WAIT βœ‹ like 3 minutes (depends on your connection)

mycomputer@usercomp:~$ pyenv install 3.8.18
Downloading Python-3.8.18.tar.xz...
-> https://www.python.org/ftp/python/3.8.18/Python-3.8.18.tar.xz
Installing Python-3.8.18...
Traceback (most recent call last):

πŸ”΄ Launch visual studio (in case it s open)

  • you need to relaunch visual studio to see the option of the new PYTHON version

you can open the top bar (to choose the interpreter) , by clicking on the bottom right (you need to open a weather.py type of file, to see the python versions at the bottom), once you see a version click on it, and the top bar will unfold


🟣 check the python versions you have on your computer

pyenv versions

output

pyenv versions
//
//
  system
  3.8.10
* 3.8.18 (set by /home/mycomputer/.pyenv/version) // βœ‹ the one i am using
//
// you can open the top bar (to choose the interpreter) , by clicking on the bottom right (you need to open a weather.py type of file, to see the python versions at the bottom), once you see a version click on it, and the top bar will unfold
  3.10.8

🌈 Switch to a Different Version:

To switch to a different version, let's say you want to switch to version 3.8.10 where Tkinter might work correctly (i will be talking about this Tkinter):

pyenv global 3.8.10

Just like that you can install different versions






🟑 pyenv (Visual Studio)

ONCE installed, the PYENV works on the global but not on the visual studio, the type of errs i get:

// good (ON GLOBAL)
in my global ~$ pyenv --version
// output
pyenv 2.4.7





// πŸ”΄ in my visual studio
// not good
LESSON_17_Virtual_Environment_and_pip$ pyenv --version
//
//
Command 'pyenv' not found, did you mean:
  command 'p7env' from deb libnss3-tools (2:3.96.1-1)
Try: sudo apt install <deb name>
Command 'pyenv' not found, did you mean:
  command 'p7env' from deb libnss3-tools (2:3.96.1-1)
Try: sudo apt install <deb name>



ChatGPT
It seems like pyenv is not recognized in the integrated terminal of Visual Studio Code
(VS Code).
This issue typically occurs because VS Code's integrated terminal does not inherit
the same environment settings as your global terminal session. Here’s how you can
resolve this issue and ensure pyenv is recognized in VS Code:

🟠 Fixing pyenv Recognition in VS Code

Verify pyenv Installation and Configuration

  • First, ensure pyenv is correctly set up in your global environment:
pyenv --version
// If this command works in your global terminal but not in VS Code, it indicates a path or environment variable issue specific to VS Code.

🟠 Setting Up VS Code to Recognize pyenv

You need to configure VS Code to use pyenv's environment settings properly.

Here’s how to do it:

  • on your VS code

shift + control + P it will open the top bar , click on the (Preferences: Open User settings JSON)

  • Click on Edit in settings.json and add the following line (replace your_username with your actual username):
    "telemetry.enableTelemetry": false,
    "telemetry.enableCrashReporter": false,

    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "[javascript]": {
      "editor.defaultFormatter": "esbenp.prettier-vscode"
    },
    "terminal.integrated.env.linux": {
        //  ADD YOURS
      "PATH": "/home/princessoftheuniverse-highlander/.pyenv/shims:${env:PATH}"
  },