Mailing List Archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] Use pyenv to have multiple versions of Python (was Re: FotoKilof gui for Imagemagick)

On Mon, 25 Jan 2021 03:05:46 +0100 (CET), wrote:

> python3 --version says: 3.8.5sudo python says:  Python 2.7.18 (default, Aug  4 2020, 11:16:42) 
> [GCC 9.3.0] on linux2
> Wow. So is there a way I can change the default? 

> Do I need to uninstall python completely and then reinstall?


> Wow. So is there a way I can change the default? 

Yes. Use pyenv.

I have multiple versions of Python installed by using pyenv.
pyenv has a command to set your default version of Python.
pyenv and pipenv play nice with each other.

I avoid installing python packages system wide.

I try to make sure that all Python packages are installed only in
virtual environments and use pipenv to deal with virtual environments
and python packages instead of using pip and virtualenv individually.

For example, to setup jupyter notebooks, I would do:

    pyenv install 3.9.1

    mkdir ~/jupyter
    cd ~/jupyter
    pipenv --python 3.9
    pipenv install jupyter
    pipenv run jupyter notebook

For example:

    j@j:~$ pyenv install 3.9.1
    pyenv: /Users/jep/.pyenv/versions/3.9.1 already exists
    continue with installation? (y/N) n
    j@j:~$ mkdir ~/jupyter2
    j@j:~$ cd ~/jupyter2
    j@j:~/jupyter2$ pipenv --python=3.9
    Creating a virtualenv for this project...
    Pipfile: /Users/jep/jupyter2/Pipfile
    Using /Users/jep/.pyenv/versions/3.9.1/bin/python3.9 (3.9.1) to create virtualenv...
    ⠇ Creating virtual environment...created virtual environment in 489ms
      creator CPython3Posix(dest=/Users/jep/.local/share/virtualenvs/jupyter2-MD1ZPYbb, clear=False, global=False)
      seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/jep/Library/Application Support/virtualenv)
        added seed packages: pip==20.3.3, setuptools==51.0.0, wheel==0.36.2
      activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

    ✔ Successfully created virtual environment!
    Virtualenv location: /Users/jep/.local/share/virtualenvs/jupyter2-MD1ZPYbb
    Creating a Pipfile for this project...
    j@j:~/jupyter2$ pipenv install jupyter
    Installing jupyter...
    Adding jupyter to Pipfile's [packages]...
    ✔ Installation Succeeded
    Pipfile.lock not found, creating...
    Locking [dev-packages] dependencies...
    Locking [packages] dependencies...
    Building requirements...
    Resolving dependencies...
    ✔ Success!
    Updated Pipfile.lock (cf969c)!
    Installing dependencies from Pipfile.lock (cf969c)...
      🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
    To activate this project's virtualenv, run pipenv shell.
    Alternatively, run a command inside the virtualenv with pipenv run.
    j@j:~/jupyter2$ pipenv run jupyter notebook
    [I 20:35:39.636 NotebookApp] The port 8888 is already in use, trying another port.
    [I 20:35:39.643 NotebookApp] Serving notebooks from local directory: /Users/jep/jupyter2
    [I 20:35:39.643 NotebookApp] Jupyter Notebook 6.2.0 is running at:
    [I 20:35:39.643 NotebookApp] http://localhost:8889/?token=186d600880dcd6e06a552f6a50f52e1031208c5944ba3e8b
    [I 20:35:39.643 NotebookApp]  or
    [I 20:35:39.643 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
    [C 20:35:39.650 NotebookApp]
        To access the notebook, open this file in a browser:
        Or copy and paste one of these URLs:
    ^C[I 20:35:59.772 NotebookApp] interrupted
    Serving notebooks from local directory: /Users/jep/jupyter2
    0 active kernels
    Jupyter Notebook 6.2.0 is running at:
    Shutdown this notebook server (y/[n])? y
    [C 20:36:01.387 NotebookApp] Shutdown confirmed
    [I 20:36:01.388 NotebookApp] Shutting down 0 kernels
    [I 20:36:01.388 NotebookApp] Shutting down 0 terminals

Home | Main Index | Thread Index