install package from tar.gz in Anaconda - python

I got *.tar.gz file and how to install that package in conda virtual environment ?
I've tried the following:
$ source activate env01
(env01)$ conda install /installers/anaconda/cassandra-driver-3.11.0.tar.gz
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- cassandra-driver-3.11.0.tar.gz
Current channels:
...
If I use pip install, it wasn't stored in environment directory. See below:
(env01)$ pip install /installers/anaconda/cassandra-driver-3.11.0.tar.gz
Processing /installers/anaconda/cassandra-driver-3.11.0.tar.gz
Requirement already satisfied: six>=1.9 in /dataplatform/software/anaconda/lib/python3.6/site-packages (from cassandra-driver==3.11.0)
Building wheels for collected packages: cassandra-driver
Running setup.py bdist_wheel for cassandra-driver ... done
Stored in directory: /home/linknet/.cache/pip/wheels/e9/ff/17/ebfd2f04dfac5206db48c1520c6f669ec225ddc2c192aada17
Successfully built cassandra-driver
Installing collected packages: cassandra-driver
Successfully installed cassandra-driver-3.11.0
My conda env01 directory is: /dataplatform/software/anaconda/envs/env01

I managed it by cloning conda env from base and install the package.
$ conda create -n env01 --clone base
Source: /dataplatform/software/anaconda
Destination: /dataplatform/software/anaconda/envs/env01
The following packages cannot be cloned out of the root environment:
- conda-4.4.10-py36_0
- conda-build-3.4.1-py36_0
- conda-env-2.6.0-h36134e3_1
Packages: 238
Files: 1
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
(env01)$ conda install /installers/anaconda/cassandra-driver-3.11.0py36_1.tar.bz2
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Now I'm able to install the package without connecting to the internet.

Related

Uninstalling conda distribution on Mac

I'm trying to uninstall the conda distribution on my Mac using the following standard commands:
conda install anaconda-clean
anaconda-clean -yes
rm -rf ~/anaconda3
rm -rf ~/.anaconda_backup
However, I keep getting the error:
Preparing transaction: done
Verifying transaction: failed
RemoveError: 'requests' is a dependency of conda and cannot be removed from
conda's operating environment.
To address the above error I try:
conda update conda
Or:
conda update --force conda
Which in turn returns:
CondaVerificationError: The package for matplotlib-inline located at appears to be corrupted. The path specified in the package manifest cannot be found.
How do I solve this error?

Conda build package to be compatible with specific python version

I am trying to create a conda package which should be compatible with all python versions greater than or equal to 3.7.
I specified this requirement in my conda.recipe/meta.yaml:
requirements:
host:
- python >=3.7
- pip
run:
- python >=3.7
- importlib-resources >=1.4.0
- ...
For my build command, I first activated a Python 3.7 conda environment, then I specified the build command should use the same environment, and I also specified that the build command should use Python 3.7 just to be safe:
$ CONDA_ENV=/path/to/py3.7/conda/env
$ conda create --yes -p $CONDA_ENV python=3.7 conda-build conda-verify importlib-resources>=1.4.0 # ...remaining reqs
$ conda activate $CONDA_ENV
$ conda build --python=3.7 -p $CONDA_ENV /path/to/package/dir
The build step in conda.recipy/meta.yaml too uses this same environment:
build:
script: bash -c 'source ~/.bashrc && conda activate /path/to/py3.7/conda/env && python -m pip install --no-deps --ignore-installed -vv /path/to/package/dir'
The problem
Running the above commands creates this file:
my-package-1.1.0-py310_0.tar.bz2
I don't get why py310 is in the package name, I did everything I can think of to make it compatible with 3.7 as well.
Here is what happens when I try to create an environment with both python 3.7 and my created package (after uploading the tar.bz2 file to my conda repo):
$ conda create -p ~/temp/conda python=3.7 my-package
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found to be incompatible with each other:
Output in format: Requested package -> Available versions
Package python conflicts for:
python=3.7
my-package -> python[version='>=3.10,<3.11.0a0']
my-package -> importlib-resources[version='>=1.4.0'] -> python[version='2.7.*|3.5.*|3.6.*|>=2.7,<2.8.0a0|>=3.8,<3.9.0a0|>=3|>=3.6|>=3.7|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|>=3.5,<3.6.0a0|3.4.*|>=3.9,<3.10.0a0|3.10.*']
The following specifications were found to be incompatible with your system:
- feature:/linux-64::__glibc==2.27=0
- feature:|#/linux-64::__glibc==2.27=0
Your installed version is: 2.27
But if I don't specify 3.7 when creating the environment it works fine, but creates an environment with 3.10.
$ conda create -p ~/temp/conda python my-package
Question
How can I make my-package compatible with Python 3.7?
After much unproductive research an unending amounts of trial and error, I found that I should have made my package not specific to any python version by adding noarch: python to my meta.yaml:
build:
noarch: python
script: bash -c 'source ~/.bashrc && conda activate /path/to/py3.7/conda/env && python -m pip install --no-deps --ignore-installed -vv /path/to/package/dir'

pip install ibm-db seems failed. keep "Getting requirements to build wheel" for minutes

my pip info
pip3 --version
pip 22.0.3 from /myPath/Python/3.8/lib/python/site-packages/pip (python 3.8)
while i install "ibm-db" for the lastest version, it shows
Defaulting to user installation because normal site-packages is not writeable
Collecting ibm-db
Using cached ibm_db-3.1.1.tar.gz (1.1 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... -
and nothing happened anymore.
what shoule I do?
thanks
Check that you have gcc and python-devel installed. If not (Assuming a Redhat derivative, something similar for others)
sudo dnf install gcc
sudo dnf install python3-devel
The pip installation seems to access some system files, despite being installed with --user, so you may have to:
sudo pip3 install --user ibm_db
You can find more info at: pypi

Package Python3.7 is not available

So I have python 3.8 and pip for it, but I want to install stable python 3.7 and pip for it also. But when I try
sudo apt-get install python3.7
It says package is not available but is referred to another package.
Help please
Error:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python3.7 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'python3.7' has no installation candidate
I tried doing the below steps in an official docker image of Kali Linux. It should work on the desktop as well.
apt-get update
apt-get install -y build-essential openssl openssl-dev* wget curl
wget https://www.python.org/ftp/python/3.7.8/Python-3.7.8.tgz
tar -xvf Python-3.7.8.tgz
cd Python-3.7.8
./configure --enable-shared
make
make test
make install
# Steps from here are to enable other libraries in linux to
# access the shared python libraries.
cd /usr/local/lib/
cp libpython3.so /usr/lib64/
cp libpython3.so /usr/lib
cp libpython3.7m.so.1.0 /usr/lib64/
cp libpython3.7m.so.1.0 /usr/lib/
cd /usr/lib64
ln -s libpython3.7m.so.1.0 libpython3.7m.so
cd /usr/lib
ln -s libpython3.7m.so.1.0 libpython3.7m.so
Done, python3.7 is installed.
root#fe794c7ff15e:~# python3
Python 3.7.8 (default, Aug 15 2020, 16:26:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
I tried creating a python virtual environment with this install. It worked properly. I was able to install pip packages as well.
(testvirtual) root#fe794c7ff15e:~# pip install flask
Collecting flask
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
|████████████████████████████████| 94 kB 404 kB/s
Collecting Jinja2>=2.10.1
Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
|████████████████████████████████| 125 kB 10.4 MB/s
Collecting click>=5.1
Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
|████████████████████████████████| 82 kB 165 kB/s
Collecting Werkzeug>=0.15
Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
|████████████████████████████████| 298 kB 11.9 MB/s
Collecting itsdangerous>=0.24
Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting MarkupSafe>=0.23
Downloading MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl (27 kB)
Installing collected packages: MarkupSafe, Jinja2, click, Werkzeug, itsdangerous, flask
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 itsdangerous-1.1.0
Default Python version in Ubuntu nowadays is 3.8 which is per-installed.
While it looks like older version of spark like 2.x versions require Python version 3.7.
I ran into same issue and I did the below
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7
Updated bashrc to point PYSPARK_PYTHON environment variable to python3.7 installed above like below
export PYSPARK_PYTHON=/usr/bin/python3.7
source ~/.bashrc
Here are the steps I follow when starting a new Python project:
First I decide on a Python release. Let's say you want to work with Python 3.7.8.
To install a specific release, I use pyenv. It's on gitbug and use this script to install it.
After installing pyenv you should cd to the place your code will be and enter pyenv install 3.7.8 and pyenv local 3.7.8 which will make sure that the Python 3.7.8 environment will be created at that location.
Then you install poetry: curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python.
After poetry is installed (use poetry -V to see if it works), you can run poetry init to create a pyproject.toml file.
You can add new dependencies like this: poetry add requests.
And you can enter that environment via poetry shell.
Now your using your new project in your specific 3.7.8 python version using your dependencies in a separate shell.
The following commands seem to work, but bear in mind the disclaimer about the deadsnakes PPA:
[T]here's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.
But, if you really want to do this:
apt-get update
apt-get install python3 python3-pip software-properties-common
add-apt-repository ppa:deadsnakes/ppa
apt-get install python3.7

Python - Where is the pip executable after install?

Since I am on a server and do not have admin privilege, I need to install my own version of python and pip locally. After installed python, I used the code python get-pip.py --user which is on the official site. I get the following return and seems pip is successfully installed. But I do not know where is the pip executable so that I cannot add it to the system environment. So where is it installed?
Collecting pip
Using cached pip-8.1.2-py2.py3-none-any.whl
Collecting setuptools
Using cached setuptools-27.2.0-py2.py3-none-any.whl
Collecting wheel
Using cached wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip setuptools wheel
On Unix, pip install --user ... drops scripts into ~/.local/bin
pip sould be somewhere around ~/.local

Categories