Conda Skeleton Installing Same Package For Different Python Versions - python

I want to install sklearn-pandas for data science on my conda environments so I switch to my Python2 Conda environment and use skeleton to build it in:
conda skeleton pypi sklearn-pandas
conda-build sklearn-pandas
conda install --use-local sklearn-pandas
The problem is, this builds in a bunch of python 3 dependencies, and at the end of it all when I run python --version I get
Python 3.6.6
This means that it had to upgrade the python version of the environment to accommodate the package it installed.
I think this library should be compatible with Python 2, it even says in its Git repo "build universal wheel compatible with python 2 and python 3".
What arguments do I need to pass to conda skeleton, build, and install so that it installs and builds it for Python 2 and doesn't do this unwanted upgrade?

Figured this out - you only need to add one flag to the conda-build step. It's:
conda-build --python 2.7 sklearn-pandas
Although in the conda skeleton stage of the installation it appears to bring in py36 packages, once you do this conda-build step with the flag it replaces them with py27.

Related

install pip on python 3.7 ubuntu

I am working on ubuntu, I have python 3.8 as standard installation.
However as my project have dependency on python 3.7 I have installed 3.7 and removed 3.8
now when I am trying to install pip it is installing python3.8 again and getting installed with 3.8.
I am using apt-get -y install pip to install pip.
I want to install pip on top of my python3.7 installation so that pip uses python3.7
my project have dependency on python 3.7
This is where virtual environments really useful. The idea is that you create an environment in which the required version of python and packages can live without altering the installation of python you might want to keep installed for other projects.
There are a few options, but Anaconda / miniconda are a popular way of using virtual environments and fairly easy to use. First you'll need to install miniconda:
https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html
After that from a terminal you need to create your new environment
conda create -n "py3p7" python=3.7
Then activate it:
conda activate py3p7
Then check that you've got pip installed and it's installed under the right python version:
pip --version
Which for me returns:
pip 22.2.2 from /home/MY_NAME/miniconda3/envs/py3p7/lib/python3.7/site-packages/pip (python 3.7)

Is it possible to install R in miniconda?

I stumbled on this post:
Install of R in miniconda
https://community.rstudio.com/t/install-of-r-in-miniconda/19755
Is it possible to install R in miniconda?
As I understand it miniconda is a package manager for Python only according to this definition:
Miniconda
Miniconda is a free minimal installer for conda. It is a small, bootstrap version of Anaconda that includes only conda, Python, the packages they depend on, and a small number of other useful packages, including pip, zlib and a few others. Use the conda install command to install 720+ additional conda packages from the Anaconda repository.
https://docs.conda.io/en/latest/miniconda.html
Or is it possible to use it with R?
I know Anaconda 3 offers R support.
Thanks.
Miniconda (the light, non-GUI version of Anaconda) gives you access to conda on the command line, and with that you can install R, along with some common packages, as follows:
conda install r r-essentials --channel conda-forge
And any further R packages you need:
conda install r-<package-name> --channel conda-forge
The "Conda" ecosystem is language-agnostic, it delivers whatever you ask for (if it exists in the repository) and installs the necessary platform binaries, but I would suggest creating a virtual environment specific to each "language platform", to ensure isolation.
Example:
conda create -n r_env r-essentials r-base
conda activate r_env
conda list
And work within this environment to run R and install new packages.
To leave the virtual environment:
conda deactivate

Updating Miniconda's Python to 3.9.x, but Miniconda is installed with Homebrew

I have installed miniconda on my machine using Homebrew (homebrew install --cask miniconda). Homebrew uses the following installer:
❯ brew info miniconda | rg miniconda:
miniconda: py38_4.9.2 (auto_updates)
i.e. with the following python version:
❯ conda info | rg "python version"
python version : 3.8.10.final.0
However, the official Miniconda installation page displays a newer version, which is shipped with Python 3.9. I guess I have three alternatives:
Manually download the newer Miniconda installation.
Wait for the Homebrew Cask Formula to be upgraded (how do I point it out to them?)
But wouldn't this delete my environments and the packages I have installed? Or can I just copy them to the new Miniconda lib/cache? Or can I upgrade Python directly from within Miniconda?
Thanks!
Or can I upgrade Python directly from within Miniconda?
Yes, it is as simple as
conda install python=3.9

Install packages in Anaconda and using it in Python 3

I want to install a library called "Scrapy" for Python on Windows. The developers recommend installing the package using Anaconda instead of Python3. However, will i be able to use the package in Python3 or will i need to use Anaconda for Web Scraping?
Anaconda is loved because it simplify package management and deployment in Python(and R, Ruby, Lua, Scala, Java, JavaScript, C/ C++, FORTRAN)
You get to keep your environment(program dependency) organized when using Anaconda.
With Anaconda, you can use any Python version, and libraries you need for a specific task. A workflow would be as follow(Assuming you have install Anaconda, and its available on your system path):
conda create -n scrap python=3.6
conda activate scrap
conda install -c conda-forge scrapy
Here we create environment called scrap with python version 3.6. We then activate it and install scrapy fron a conda channel forge.
While in this environment(scrap), you have access to Python 3.6 and scrapy. The best thing about this is that this is separate from your other Python and packages.
To get out of your environment,
conda deactivate
While in your environment, you can use both conda and pip to install packages to that environment. Always try finding packages in conda(plus it’s channels) before using pip, becsusr conda will check for packages compatabilities before installation. It will know which packages to upgrade or downgrade to avoid conflicts.
In few cases where a package is not in conda, then use pip.
Read more:
https://conda.io/docs/index.html
Anaconda is a python distribution which contains additional packages to the python it ships with. To have lightweight version of python (without many additional packages), you can install Miniconda. Anaconda and Miniconda come with the conda package manager. You can use it to install and update packages specific to its python distribution.
To install scrapy package using Anaconda / Miniconda, in the Windows Command Prompt simply type in:
conda install scrapy
In Anaconda you can install almost all python packages using conda install or pip install.
You have to goto Anaconda prompt and type in pip install Scrapy
Anaconda just simplified the installation, but you can also install scrapy through PyPi as
pip install scrapy

How to downgrade conda version?

I need to downgrade my conda version from 4.3 to 4.2 on my CentOS 6.7 machine.
What is the command required to do that?
I wouldn't recommend downgrading conda except when the newly installed (upgraded) version has a critical bug.
But since you asked: You can specify a version by appending ={version} to the packages, this works even for the conda package:
$ conda install conda=4.2
If you want a specific 4.2 version you can also use (for example):
$ conda install conda=4.2.15
Note that downgrading conda can be very risky. After the downgrade your conda could fail completely or work incorrectly. Conda uses a lot of metadata that evolve over time ... so if the downgraded conda version cannot make sense of these - or even worse corrupt them - you'll have a painful experience in how to recover your conda environemnt. Downgrade conda at your own risk (and in my opinion only if really, really necessary)!
In case you already downgraded conda and it's throwing exceptions (for example CondaUpgradeError) at you, then maybe this "section" in an troubleshooting guide in the conda repository may be useful:
Conda upgrade error
Cause
Downgrading conda from 4.6.1 to 4.5.x and then trying to conda install conda or conda upgrade conda will produce a solving and upgrade error similar to the following:
Solving environment: failed
CondaUpgradeError: This environment has previously been operated on by a
conda version that's newer than the conda currently being used. A newer
version of conda is required.
target environment location: /opt/conda
current conda version: 4.5.9
minimum conda version: 4.6
Solution
Change the .condarc file. Set the parameter by editing the .condarc file directly: allow_conda_downgrades: true in conda version 4.5.12. This will then let you upgrade. If you have something older than 4.5.12, install conda 4.6.1 again from the package cache.
EXAMPLE: If my conda info says package cache : /opt/conda/pkgs and my Python version is 3.7, then on the command line, type conda install /opt/conda/pkgs/conda-4.6.1-py37_0.tar.bz2 to resolve the issue.

Categories