issue148:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue148:python [2019/09/02 11:46] – créée auntiee | issue148:python [2019/09/17 15:38] (Version actuelle) – lecastillan | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Last month, I talked about Python 3.8.0b2 and I suggested that if you wanted to try it, you should consider a virtual environment. I then realized that I hadn't really discussed virtual environments before. So, I'm going to now. | + | **Last month, I talked about Python 3.8.0b2 and I suggested that if you wanted to try it, you should consider a virtual environment. I then realized that I hadn't really discussed virtual environments before. So, I'm going to now.** |
- | What is a Python | + | Le mois dernier, j'ai parlé de Python |
- | Basically, it allows you to manage multiple versions of Python (and pip) easily, without messing up any of the packages or configurations that you already have. Why would you have multiple versions of Python? I know my environment | + | **What |
- | What' | + | Basically, it allows you to manage multiple versions of Python (and pip) easily, without messing up any of the packages or configurations that you already have. Why would you have multiple versions of Python? I know my environment is probably somewhat different from your needs, but I have multiple machines, and on each, my " |
- | I found a project called pyenv that pretty much does everything you need without much pain. You can find it at https:// | + | Qu'est-ce qu'un environnement virtuel en Python ? |
- | Getting Started | + | En gros, il vous permet de gérer facilement des versions multiples de Python (et de pip), sans semer la pagaille dans les paquets et les configurations que vous avez déjà. Pourquoi auriez-vous plusieurs configurations de Python ? Je sais que mon environnement est probablement quelque peu éloigné de vos besoins, mais j'ai plusieurs machines et, sur chacune, ma version « principale » de Python est, soit la 3.6, soit la 3.7, selon ce que je fais. Par exemple, j'ai une instance de Python 3.6 pour la programmation de l' |
+ | |||
+ | **What' | ||
+ | |||
+ | I found a project called pyenv that pretty much does everything you need without much pain. You can find it at https:// | ||
+ | |||
+ | Quelle est la solution ? | ||
+ | |||
+ | J'ai trouvé un projet appelé pyenv qui fait plutôt bien tout ce dont vous avez besoin sans trop de peine. Vous pouvez le trouver sur https:// | ||
+ | |||
+ | **Getting Started | ||
I'll limit my instructions to those for a PC using Ubuntu/ | I'll limit my instructions to those for a PC using Ubuntu/ | ||
- | There are two ways to install pyenv. There is an easy way and a hard way. I'm going to discuss the easy way. The reason for this is that the easy way not only installs pyenv, but also installs some other pyenv tools that will be helpful – like pyenv-virtualenv, | + | There are two ways to install pyenv. There is an easy way and a hard way. I'm going to discuss the easy way. The reason for this is that the easy way not only installs pyenv, but also installs some other pyenv tools that will be helpful – like pyenv-virtualenv, |
- | The first thing you need to do is install the dependencies. You probably have most of them, but run the install command below just to be safe. Open a terminal and enter... | + | Mise en route |
+ | |||
+ | Je limiterai mes instructions à celles pour un PC utilisant Ubuntu/ | ||
+ | |||
+ | Il y a deux façons d' | ||
+ | |||
+ | **The first thing you need to do is install the dependencies. You probably have most of them, but run the install command below just to be safe. Open a terminal and enter... | ||
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ | sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ | ||
Ligne 24: | Ligne 40: | ||
Now you need to make a decision on where you are going to install pyenv. I suggest you put it into the home directory. Change to whatever directory you choose, and enter: | Now you need to make a decision on where you are going to install pyenv. I suggest you put it into the home directory. Change to whatever directory you choose, and enter: | ||
+ | |||
+ | $ curl https:// | ||
+ | |||
+ | La première chose que vous devez faire est d' | ||
+ | |||
+ | 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 | ||
+ | |||
+ | Maintenant vous devez décider de l' | ||
$ curl https:// | $ curl https:// | ||
- | This runs the installer for pyenv. Close your terminal and reopen it. This loads any changes to the .bashrc file, or, alternatively, | + | **This runs the installer for pyenv. Close your terminal and reopen it. This loads any changes to the .bashrc file, or, alternatively, |
$ source ~/.bashrc | $ source ~/.bashrc | ||
Ligne 37: | Ligne 65: | ||
and add the following lines (next page, top right) to the bottom of the file. | and add the following lines (next page, top right) to the bottom of the file. | ||
- | Make sure that the first line defining the PYENV_ROOT points to the correct directory. | + | Make sure that the first line defining the PYENV_ROOT points to the correct directory.** |
- | Save your .bashrc file and reload it. As before, this can be done by either closing and re-opening the terminal, or by simply typing: | + | |
+ | Cela lance l' | ||
+ | |||
+ | $ source ~/.bashrc | ||
+ | |||
+ | Vous avez besoin, ensuite, de modifier le fichier .bashrc. Si vous utilisez une version différente, | ||
+ | |||
+ | $ gedit ~/.bashrc | ||
+ | |||
+ | et ajoutez les lignes suivantes (page suivante, en haut à droite) en bas du fichier. | ||
+ | |||
+ | Assurez-vous que la première ligne, définissant PYENV_ROOT, pointe sur le bon répertoire. | ||
+ | |||
+ | **Save your .bashrc file and reload it. As before, this can be done by either closing and re-opening the terminal, or by simply typing: | ||
$ source ~/.bashrc | $ source ~/.bashrc | ||
Ligne 47: | Ligne 88: | ||
Now we have to install a version of Python. Right now, let's do the latest version of 3.7, which is 3.7.4. Again in your terminal window, type: | Now we have to install a version of Python. Right now, let's do the latest version of 3.7, which is 3.7.4. Again in your terminal window, type: | ||
+ | |||
+ | $ pyenv install --list** | ||
+ | |||
+ | Sauvegardez votre fichier .bashrc et rechargez-le. Comme précédemment, | ||
+ | |||
+ | $ source ~/.bashrc | ||
+ | |||
+ | Cela force le rechargement de .bashrc. Maintenant, juste pour terminer, lancez une mise à jour de pyenv. | ||
+ | |||
+ | $ pyenv update | ||
+ | |||
+ | Nous devons maintenant installer une version de Python. À l' | ||
$ pyenv install --list | $ pyenv install --list | ||
- | This will list all of the available packages that you can install. It's a VERY long list, with the actual Python versions near the top. You'll also see versions of jython, ironpython, anaconda and anaconda3, activepython, | + | **This will list all of the available packages that you can install. It's a VERY long list, with the actual Python versions near the top. You'll also see versions of jython, ironpython, anaconda and anaconda3, activepython, |
To install, type: | To install, type: | ||
Ligne 63: | Ligne 116: | ||
You should see something like this... | You should see something like this... | ||
+ | |||
+ | $ pyenv versions | ||
+ | system | ||
+ | * 3.7.4 (set by / | ||
+ | |||
+ | Vous obtiendrez ainsi une liste de tous les paquets disponibles que vous pouvez installer. C'est une TRÉS longue liste, avec les versions actuelles de Python au début. Vous verrez aussi les versions de jython, ironpython, anaconda et anaconda3, activepython et d' | ||
+ | |||
+ | Pour l' | ||
+ | |||
+ | $ pyenv install 3.7.4 | ||
+ | |||
+ | Ça prend environ cinq minutes sur mon vieux portable ; aussi, allez prendre une tasse de café ou de thé, puis reprenez. | ||
+ | |||
+ | Une fois l' | ||
+ | |||
+ | $ pyenv versions | ||
+ | |||
+ | Vous devriez voir quelque chose comme ceci... | ||
$ pyenv versions | $ pyenv versions | ||
Ligne 68: | Ligne 139: | ||
* 3.7.4 (set by / | * 3.7.4 (set by / | ||
- | A couple of things here to note. First, you'll see * 3.7.4 which lets you know which version is set as the current default version of Python when using pyenv. Next, there is a " | + | **A couple of things here to note. First, you'll see * 3.7.4 which lets you know which version is set as the current default version of Python when using pyenv. Next, there is a " |
$ python -V | $ python -V | ||
Ligne 75: | Ligne 146: | ||
Now, you can always see what versions that pyenv has installed by doing a: | Now, you can always see what versions that pyenv has installed by doing a: | ||
+ | |||
+ | $ ls ~/ | ||
+ | |||
+ | Plusieurs choses à noter ici. D' | ||
+ | |||
+ | $ python -V | ||
+ | |||
+ | Vous devriez voir la version que vous utilisez normalement. | ||
+ | |||
+ | Bon. Vous pouvez toujours voir les versions que pyenv a installées, | ||
$ ls ~/ | $ ls ~/ | ||
- | This is where all of the pyenv Python versions are located. If you ever want to delete one, simply type: | + | **This is where all of the pyenv Python versions are located. If you ever want to delete one, simply type: |
rm -rf ~/ | rm -rf ~/ | ||
Ligne 91: | Ligne 172: | ||
But don't do that yet. Let's tell pyenv that we want to use the 3.7.4 version we just installed. | But don't do that yet. Let's tell pyenv that we want to use the 3.7.4 version we just installed. | ||
+ | |||
+ | $ pyenv local 3.7.4** | ||
+ | |||
+ | C'est là que sont situées toutes les versions de python dans pyenv. Si vous voulez en supprimer une, il suffit de taper : | ||
+ | |||
+ | rm -rf ~/ | ||
+ | |||
+ | dans une fenêtre de terminal. Par exemple, si je voulais supprimer la version 3.7.4, je ferai : | ||
+ | |||
+ | $ rm -rf ~/ | ||
+ | |||
+ | Ou vous pouvez le faire avec une commande de pyenv : | ||
+ | |||
+ | $ pyenv uninstall 3.7.4 | ||
+ | |||
+ | Mais ne le faites pas encore. Disons à pyenv que nous voulons utiliser la version 3.7.4 que nous venons d' | ||
$ pyenv local 3.7.4 | $ pyenv local 3.7.4 | ||
- | Now ask python what version it is... | + | **Now ask python what version it is... |
$ python -V | $ python -V | ||
Ligne 107: | Ligne 204: | ||
$ pyenv local system | $ pyenv local system | ||
+ | $ python -V** | ||
+ | |||
+ | Demandez maintenant à python la version qui est installée... | ||
+ | |||
$ python -V | $ python -V | ||
- | You should see your normal Python instance restored. Now, let's install the latest version of 3.8.0 in pyenv (which, at this writing, is 3.8.0b2). | + | Vous devriez voir quelque chose comme ceci... |
+ | |||
+ | Python 3.7.4 | ||
+ | |||
+ | Sinon, essayez de faire « exec $SHELL », puis réessayez. | ||
+ | |||
+ | Histoire de bien comprendre, revenez maintenant à la version du système. | ||
+ | |||
+ | $ pyenv local system | ||
+ | $ python -V | ||
+ | |||
+ | **You should see your normal Python instance restored. Now, let's install the latest version of 3.8.0 in pyenv (which, at this writing, is 3.8.0b2). | ||
$ pyenv install 3.8-dev | $ pyenv install 3.8-dev | ||
Ligne 121: | Ligne 233: | ||
Finally, let's make sure that we are using the correct pip – so we can install some libraries... | Finally, let's make sure that we are using the correct pip – so we can install some libraries... | ||
+ | |||
+ | $ pyenv which pip** | ||
+ | |||
+ | Vous devriez voir que votre instance normale de Python a été rétablie. Maintenant, installons dans pyenv la dernière version de la 3.8.0 (qui est la 3.8.0b2, à l' | ||
+ | |||
+ | $ pyenv install 3.8-dev | ||
+ | |||
+ | Après environ 5 minutes, tout est installé. Pour le vérifier, faites ceci : | ||
+ | |||
+ | $ pyenv versions | ||
+ | $ pyenv local 3.8-dev | ||
+ | $ python -V | ||
+ | |||
+ | Enfin, assurons-nous que nous utilisons le bon pip - ainsi, nous pourrons installer quelques bibliothèques... | ||
$ pyenv which pip | $ pyenv which pip | ||
- | You should see something like: | + | **You should see something like: |
/ | / | ||
Ligne 138: | Ligne 264: | ||
and you should see... | and you should see... | ||
+ | |||
+ | Package | ||
+ | ---------- ------- | ||
+ | pip 19.0.3 | ||
+ | setuptools 40.8.0** | ||
+ | |||
+ | Vous devriez voir quelque chose comme : | ||
+ | |||
+ | / | ||
+ | |||
+ | et pour mieux nous le prouver... | ||
+ | |||
+ | $ pip --version | ||
+ | pip 19.0.3 from / | ||
+ | |||
+ | Ainsi, nous savons maintenant que notre version de Python est la 3.8.0b2 et que le pip que nous utilisons vient aussi de Python 3.8. Comme d' | ||
+ | |||
+ | $ pip list | ||
+ | |||
+ | et vous devriez voir... | ||
Package | Package | ||
Ligne 144: | Ligne 290: | ||
setuptools 40.8.0 | setuptools 40.8.0 | ||
- | You might also get a notice to upgrade pip. Go ahead and do that if you want, then we'll set up a virtual environment. | + | **You might also get a notice to upgrade pip. Go ahead and do that if you want, then we'll set up a virtual environment. |
Notice that we are using " | Notice that we are using " | ||
Ligne 153: | Ligne 299: | ||
and the response should be something like: | and the response should be something like: | ||
+ | |||
+ | Looking in links: / | ||
+ | Requirement already satisfied: setuptools in / | ||
+ | Requirement already satisfied: pip in / | ||
+ | |||
+ | Vous pourriez recevoir aussi un message vous demandant de mettre pip à jour. Allez-y ; faîtes-le si vous voulez et ensuite nous paramétrerons un environnement virtuel. | ||
+ | |||
+ | Notez que nous utilisons « pip » et non « pip3 ». Que vous utilisiez l'un ou l' | ||
+ | |||
+ | Maintenant, nous allons traiter l' | ||
+ | |||
+ | $ pyenv virtualenv 3.8-dev 38beta | ||
+ | |||
+ | et la réponse devrait être quelque chose comme ça : | ||
Looking in links: / | Looking in links: / | ||
Ligne 158: | Ligne 318: | ||
Requirement already satisfied: pip in / | Requirement already satisfied: pip in / | ||
- | Now we want to activate our virtual environment | + | **Now we want to activate our virtual environment |
$ pyenv activate 38beta | $ pyenv activate 38beta | ||
Ligne 167: | Ligne 327: | ||
(38beta) greg@greg-Latitude-E5500: | (38beta) greg@greg-Latitude-E5500: | ||
- | The first thing you should notice is the (38beta) that appears before your prompt. This lets you know that you are now in the virtual environment 38beta. Next, notice the warning notice above. This says that the prompt change will be going away in some future version. Many users are trying to get the maintainers of pyenv to change their minds, since this can tell you what, if any, virtual environment you are using just at a glance. | + | The first thing you should notice is the (38beta) that appears before your prompt. This lets you know that you are now in the virtual environment 38beta. Next, notice the warning notice above. This says that the prompt change will be going away in some future version. Many users are trying to get the maintainers of pyenv to change their minds, since this can tell you what, if any, virtual environment you are using just at a glance.** |
+ | |||
+ | Maintenant nous voulons activer notre environnement virtuel : | ||
+ | |||
+ | $ pyenv activate 38beta | ||
+ | |||
+ | Vous devriez obtenir : | ||
+ | |||
+ | pyenv-virtualenv: | ||
+ | (38beta) greg@greg-Latitude-E5500: | ||
+ | |||
+ | La première chose que vous devez noter, c'est le (38beta) qui apparaît avant votre invite. Cela vous permet de savoir que vous êtes maintenant dans l' | ||
- | Now, verify you are using the correct python version… | + | **Now, verify you are using the correct python version… |
$ python -V | $ python -V | ||
Ligne 183: | Ligne 354: | ||
$ pyenv deactivate | $ pyenv deactivate | ||
- | This should reset the prompt back to its " | + | This should reset the prompt back to its " |
- | At this point, you should now be able to move around using different Python versions pretty easily, activate and deactivate your virtual environments, | + | Maintenant vérifiez que vous utilisez la bonne version de python... |
+ | |||
+ | $ python -V | ||
+ | Python 3.8.0b2+ | ||
+ | |||
+ | Et vérifiez que la version de pip pointe sur la bonne installation de python... | ||
+ | |||
+ | (38beta) greg@greg-Latitude-E5500: | ||
+ | pip 19.1.1 from / | ||
+ | |||
+ | Pour sortir de l' | ||
+ | |||
+ | $ pyenv deactivate | ||
+ | |||
+ | Cela remettra l' | ||
+ | |||
+ | **At this point, you should now be able to move around using different Python versions pretty easily, activate and deactivate your virtual environments, | ||
I should say that whatever you do, don't use python 3.8.0 for any serious production work until the full release comes out sometime in October or November. The actual release is currently scheduled for October 21, 2019. Here is the schedule as of now... | I should say that whatever you do, don't use python 3.8.0 for any serious production work until the full release comes out sometime in October or November. The actual release is currently scheduled for October 21, 2019. Here is the schedule as of now... | ||
Ligne 197: | Ligne 384: | ||
3.8.0 candidate 2: Monday, 2019-10-07 (if necessary) | 3.8.0 candidate 2: Monday, 2019-10-07 (if necessary) | ||
- | 3.8.0 final: Monday, 2019-10-21 | + | 3.8.0 final: Monday, 2019-10-21** |
+ | |||
+ | À ce stade, vous devriez être capable de passer d'une version de Python à une autre assez facilement, d' | ||
+ | |||
+ | Je dirais que, quoique vous fassiez, n' | ||
+ | |||
+ | 3.8.0 beta 3 : lundi 29-07-2019 | ||
+ | |||
+ | 3.8.0 beta 4 : lundi 26-08-2019 | ||
+ | |||
+ | 3.8.0 candidate 1 : lundi 30-09-2019 | ||
+ | |||
+ | 3.8.0 candidate 2 : lundi 07-10-2019 (si nécessaire) | ||
+ | |||
+ | 3.8.0 final : lundi 21-10-2019 | ||
+ | |||
+ | |||
+ | **If you want to keep up with the latest beta and release candidates within your pyenv world, when a new version is released, give it a day or two before you try to nstall the new one. Get a list from pip of the library packages you have installed in your beta setup (pip list > pippkgs38beta.txt), | ||
- | If you want to keep up with the latest beta and release | + | Si vous voulez vous tenir au courant des dernières RC (release |
issue148/python.1567417568.txt.gz · Dernière modification : 2019/09/02 11:46 de auntiee