![]() (You might want to investigate other Python distributions later, since they address specific use cases you might have, but we won’t consider them here.) Again, this is the safest and most broadly compatible distribution, the one nobody gets fired for picking. Unlike Linux, though, Python offers one, gold-standard, “official” edition you can always fall back on: CPython, the version provided by the Python Software Foundation at. Python also comes in a variety of distributions, in much the same way Linux does. You can always try out the most recent version of Python in a controlled way - e.g., in a VM or a test machine - but going one version back guarantees the best compatibility with common third-party Python packages. The safe bet, then, is to use the latest update of Python 3.7 (in this case, Python 3.7.6). Which sets the Python version to the correct one.At the time of this writing, Python 3.8.1 is the most current version. Now, when someone wants to use your project, they will do: pyenv local python-version containing the version string.Īnd now let's install a package locally just for our project: TODO: there is no nice way it seems: Pyenv choose virtualenv directory Then, from inside your project directory, set the desired python version with: pyenv local 3.8.0 This is how to do it.įirst install your desired Python version as before. However, what you usually want is to set a specific python and package version on a per-project basis. In the previous section, we saw how to use pyenv in a global setup. Gives: /home/ciro/.pyenv/versions/3.8.0/lib/python3.8/site-packages/cowsay/_init_.py We can confirm that everything is locally installed in our clean environemnt with: python -c 'import cowsay print(cowsay._file_)' Python -c 'import cowsay cowsay.tux("Python is fun")' We can now proceed to install and use packages normally: pip install cowsay Select a different python version: pyenv global 3.8.0 We now have: * system (set by /home/cirsan01/.pyenv/version) List available Python versions: pyenv versions # Build and install a Python version from source. ![]() Xz-utils tk-dev libffi-dev liblzma-dev python-openssl git Libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \ Sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \ ![]() Install the python version you want: # Increase the chances that the build will have all dependencies. bashrc: export PATH="$/.pyenv/bin:$PATH"įind Python version to install: pyenv install -list Pyenv allows you to manage multiple Python versions without sudo for a single user, much like Node.js NVM and Ruby RVM. Virtualenv does feature a "-help" switch to help you, but you basically do: $ virtualenv -p Īnd there you are - all things using Python will "see" the interpreter in the virtualenv, due to environment variables set. Activate your virtualenv, and install Python packages using pip on it.Use virtualenv to create an environment from which you will use your different Python version.use your system's package manager to install "python-setuptools" and "python-virtualenv" (not sure if these are the actual package names).In short, once you have compiled your desired version of Python, do this: So the above method apply as a recommendation even if your system do have more than one version of Python available on apt-get. (It is also a mess to find the module files themselves in a Debian or Ubuntu). This mostly works, but they mess with Python's default directory hierarchy, and some applications fail to use Python in this way. Note that the Debian - and Ubuntu - systems devised a way to run parallel official Python's in /usr, and to have apt-get to install Python packages to both Python versions at once. (And even if one opt to live boldly and not use virtualenvs, installing another python version on the same prefix ( /usr, and even /usr/local) than your system's Python is a source to confusing errors and conflicts). And install other versions of Python (or even the same), to be run with "virtualenv"s - on these other install you install things with pip/setuptools only. So, one of the less error prone way to deal with it is to have separate Python installs in your system - leave the python that came with the system for system scripts and such - on this python, make use of packages installed by your package manager only. The repository is the Pypi - Python Package Index, and packages are installed with pip or the easy_install script, which is part of Python's setuptools package.Īs a rule of thumb, you should not use both the packages installed via pip/setuptools, and packages available to your distro (via apt-get, yum, urpmi, etc.) as they might conflict. ![]() Python has got its own package managing facilities, in parallel to the one sets by the Linux distributions (including Ubuntu).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |