My Ubuntu system is on python 2.7.15
conda install -c anaconda flask
Anaconda always installs python 3.5 with Flask and other packages. How can I not install python 3.7 and leave python 2.7.15 as is when installing anaconda packages?
The Python you install with anaconda does not interfere at all with your system Python. You can use Anaconda to have multiple Pythons (in multiple conda environments) besides the system Python. You just have to make sure which one is invoked when you run scripts and make sure it's the one you intended.
To answer the "literal" question you asked, you can specify the Python version when installing something:
conda install -c anaconda flask python=2
This will keep your Python at version 2 or report a mismatch if the package you want to install isn't available on anaconda for Python 2. The number of packages dropping Python 2 support is increasing because Python 2 is near it's "end of life", so don't expect to get latest or even near-latest releases of the packages when keeping at Python 2.
Personally I would recommend to create a different environment instead of trying to install to much into the base environment:
conda create -n mypython2environment python=2 flask
And by activating that environment you should be able to use the packages you installed in that environment:
activate mypython2environment
Several IDEs have built-in support for conda environments, so these may be helpful (especially in making sure you use the correct environment and thus the correct Python).
Related
So the default of anaconda is python 3.8, but you can invoke python2 by running python2 a_py_script.py. The issue comes from the fact that you'll need to import things (say biopython), and you can't import them as any conda install -c conda-forge biopython or pip install biopython will be understood to automatically slot it into python3.8 packages exclusively.
I ask this because I have some python2.7 scripts that demand packages outside the default install scope and ideally I'd like to do this without having to create a new python=2.7 env and track down everything I need.
I've tried pip2.7 install biopython and python2.7 -m pip install biopython to no avail. Could it be that I technically don't have python 2.7 even though I'm able to invoke it from command line via python2 because python3 just naturally has some special limited backwards compatibility to run my python2 scripts? (I did notice that conda list includes only 3.8 and no mention of 2.7)
I've tried cloning my env but I don't know how to do it in such a way that swapts just the version of python. conda create --name py27test --clone base python=2.7 says too many arguments. I'd like to know if this is even advisible as my base environment I would presume is entirely built off of v3.8 so swapping out the python versions will just be bad time hence why this seems impossible?
You can't mix Python versions in a conda environment. You can call Python executables from outside your environment, but that's unadvisable for anything requiring dependencies. If you must use Python 2.7 and need dependencies installed, that needs to be done in a contained environment, one that does not mix Python 3 packages into it.
If you care about using your Python 2.7 scripts long-term, you should consider migrating them now; using unsupported software is only going to get harder over time.
I'm using msys2 for my dev environment on Windows 10. It's great, and this is the first roadblock I've come up against.
Specifically I'm trying to install some packages that won't allow me to via pip because my platform is incorrect. They require a 3.6 platform and msys2 comes with 3.7
I tried pyenv-win, but that wouldn't seem to work within cmder and it also installed some full windows installers of python 3.6.
Is there a recommended way to get another version of python installed using the msys ecosystem of command lines?
I know you want to use msys2, but you should reconsider, the majority of implementation don’t use msys2. multiple versions and multiple environments can get complicated. If you choose to go forward in a more standard way, you could use what I have written below
You can’t create a virtual env with a version of python that isn’t install in your system.
Downloaded and install the version of python you want to use, from https://www.python.org/
Create a project folder
Create a venv calling the newly installed version of python
venv is part of the standard library
c:\>python -3.x -m venv c:\path\to\myenv
it created a copy of the python executable in the newly created venv
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Activate the new env
c:\> c:\path\to\myenv\Scripts\activate.bat
(venv) path\to\myenv>
Once activated you can pip install
(venv) path\to\myenv> pip install [package.name]
(venv) path\to\myenv> pip list
Any script you run from that venv will used the python exe installed in that virtual environment and use the packages you just installed there
In my Ubuntu 14.04 computer, I have installed two kinds of Python, one is called native python, which comes along with the Ubuntu operating system, and the other is the conda version, which is installed after I installed the conda package.
If I launch python command, the default python refers to the conda version.
Using conda can bring a lot of advantages for package management. But before I installed conda, I have already installed some Python modules with the native Python by using pip install command. These modules, however, are not reachable by conda Python. So, here is my question: how can I set conda so that it can use the packages managed by native python?
When I ask this question, I cannot help asking another questions:
Is it a good practice to mix packages managed by conda and native python? Any practice I can follow?
How can I switch Python to native Python?
It is not a good practice to mix packages managed by conda and native python. You can still, however, install Python modules using pip into Anaconda. I would recommend strictly using Anaconda (and use conda virtual environments as well as the conda package manager), and not using native python any longer.
Your best bet is to use strictly Anaconda moving forward. I would reinstall the packages into a conda virtual environment.
conda create --name NAME_HERE
or
conda create --name NAME_HERE --clone root if you want to include all packages that come with Anaconda by default.
Then switch to your new environment with source activate NAME_HERE (Linux, macOS) or activate NAME_HERE (Windows). Then you can install packages with both the conda package manager and pip.
See the conda docs on managing conda virtual environments for details.
Kind user #MikhailKnyazev has pointed out that this is how you would use the packages managed by native python. It is still not recommended.
Although it is certainly not a good practice, it is useful to know
that you can add system-side packages inside virtual environment by
symlinking them like this: ln -s /usr/lib/<PYTHON_VER>/dist-packages/<PACKAGE> <virtualenv_path>/lib/<PYTHON_VER>/site-packages/
I am a ruby programmer trying to learn python. I am pretty familiar with pyenv since it is like a copy and paste from rbenv. Pyenv helps allow to have more than one version of python in a system and also to isolate the python without touching sensitive parts of system.
I suppose every python installation comes with pip package. What I still don't understand is, there are many good python libs out there that suggest to use this virtualenv and anaconda. I can even find a virtualenv plugin for pyenv.
Now I am getting confused with the purpose of these two pyenv and virtualenv.
worse inside pyenv there is a virtualenv plugin.
My questions are:
what is the difference between pyenv and virtualenv?
Is there any difference in using pip command inside both pyenv and virtualenv?
what does this pyenv virutalenv do?
Your explanation with example will be highly appreciated.
Edit: It's worth mentioning pip here as well, as conda and pip have similarities and differences that are relevant to this topic.
pip: the Python Package Manager.
You might think of pip as the python equivalent of the ruby gem command
pip is not included with python by default.
You may install Python using homebrew, which will install pip automatically: brew install python
The final version of OSX did not include pip by default. To add pip to your mac system's version of python, you can sudo easy_install pip
You can find and publish python packages using PyPI: The Python Package Index
The requirements.txt file is comparable to the ruby gemfile
To create a requirements text file, pip freeze > requirements.txt
Note, at this point, we have python installed on our system, and we have created a requirements.txt file that outlines all of the python packages that have been installed on your system.
pyenv: Python Version Manager
From the docs: pyenv lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well. This project was forked from rbenv and ruby-build, and modified for Python.
Many folks hesitate to use python3.
If you need to use different versions of python, pyenv lets you manage this easily.
virtualenv: Python Environment Manager.
From the docs: The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform’s standard location is), it’s easy to end up in a situation where you unintentionally upgrade an application that shouldn’t be upgraded.
To create a virtualenv, simply invoke virtualenv ENV, where ENV is is a directory to place the new virtual environment.
To initialize the virtualenv, you need to source ENV/bin/activate. To stop using, simply call deactivate.
Once you activate the virtualenv, you might install all of a workspace's package requirements by running pip install -r against the project's requirements.txt file.
Anaconda: Package Manager + Environment Manager + Additional Scientific Libraries.
**Anaconda is a commercial distribution of Python with the most popular python libraries, you are not permitted to use Anaconda in an organisation with more than 200 employees.
From the docs: Anaconda 4.2.0 includes an easy installation of Python (2.7.12, 3.4.5, and/or 3.5.2) and updates of over 100 pre-built and tested scientific and analytic Python packages that include NumPy, Pandas, SciPy, Matplotlib, and IPython, with over 620 more packages available via a simple conda install <packagename>
As a web developer, I haven't used Anaconda. It's ~3GB including all the packages.
There is a slimmed down miniconda version, which seems like it could be a more simple option than using pip + virtualenv, although I don't have experience using it personally.
While conda allows you to install packages, these packages are separate than PyPI packages, so you may still need to use pip additionally depending on the types of packages you need to install.
See also:
conda vs pip vs virtualenv (section in documentation from anaconda)
the difference between pip and conda (stackoverflow)
the relationship between virtualenv and pyenv (stackoverflow)
Simple analogy:
pyenv ~ rbenv
pip ~ bundler
virtual env ~ gemset in rvm. This can be managed by bundler directly without gemset.
Since I use python3 I prefer the python3 built-in virtual environment named venv. venv is simple and easy to use. I would recommend you to read its official docs. The doc is short and concise.
In ruby, we don't really need a virtual environment because the bundler takes care of it. Both virtual env and bundler are great, however, they have different solutions to solve the same problem.
Simple explanation: https://docs.conda.io/projects/conda/en/latest/commands.html#conda-vs-pip-vs-virtualenv-commands
If you have used pip and virtualenv in the past, you can use conda to perform all of the same operations.
Pip is a package manager
virtualenv is an environment manager
Conda is both
I'm relatively new in macOS. I've just installed XCode (for c++ compiler) and Anaconda with the latest Python 3 (for myself). Now I'm wondering how to install properly second Anaconda (for work) with Python 2?
I need both versions to work with iPython and Spyder IDE. Ideal way is to have totally separate Python environments. For example, I wish I could write like conda install scikit-learn for Python 3 environment and something like conda2 install scikit-learn for Python 2.
There is no need to install Anaconda again. Conda, the package manager for Anaconda, fully supports separated environments. The easiest way to create an environment for Python 2.7 is to do
conda create -n python2 python=2.7 anaconda
This will create an environment named python2 that contains the Python 2.7 version of Anaconda. You can activate this environment with
source activate python2
This will put that environment (typically ~/anaconda/envs/python2) in front in your PATH, so that when you type python at the terminal it will load the Python from that environment.
If you don't want all of Anaconda, you can replace anaconda in the command above with whatever packages you want. You can use conda to install packages in that environment later, either by using the -n python2 flag to conda, or by activating the environment.
Edit!: Please be sure that you should have both Python installed on your computer.
Maybe my answer is late for you but I can help someone who has the same problem!
You don't have to download both Anaconda.
If you are using Spyder and Jupyter in Anaconda environmen and,
If you have already Anaconda 2 type in Terminal:
python3 -m pip install ipykernel
python3 -m ipykernel install --user
If you have already Anaconda 3 then type in terminal:
python2 -m pip install ipykernel
python2 -m ipykernel install --user
Then before use Spyder you can choose Python environment like below!
Sometimes only you can see root and your new Python environment, so root is your first anaconda environment!
Also this is Jupyter. You can choose python version like this!
I hope it will help.
This may be helpful if you have more than one python versions installed and dont know how to tell your ide's to use a specific version.
Install anaconda. Latest version can be found here
Open the navigator by typing anaconda-navigator in terminal
Open environments. Click on create and then choose your python version in that.
Now new environment will be created for your python version and you can install the IDE's(which are listed there) just by clicking install in that.
Launch the IDE in your environment so that that IDE will use the specified version for that environment.
Hope it helps!!