Cannot get python packages to work - python

I am trying to calculate levenshtein distance between 2 strings. Tried to install 2 packages (python-levenshtein) and pylev
Used ananconda (on Win 64 machine) for the install
conda install -c https://conda.anaconda.org/trent pylevenshtein
It looks like the package got installed
Fetching package metadata: ......
Solving package specifications: ..............
Package plan for installation in environment C:\Anaconda2:
The following packages will be downloaded:
package | build
---------------------------|-----------------
pylevenshtein-0.10.1 | py27_0 34 KB
setuptools-20.1.1 | py27_0 674 KB
------------------------------------------------------------
Total: 707 KB
The following NEW packages will be INSTALLED:
pylevenshtein: 0.10.1-py27_0
The following packages will be UPDATED:
setuptools: 19.6.2-py27_0 --> 20.1.1-py27_0
Proceed ([y]/n)? y
Fetching packages ...
pylevenshtein- 100% |###############################| Time: 0:00:0042.36 kB/s
setuptools-20. 100% |###############################| Time: 0:00:02 320.43 kB/s
Extracting packages ...
[ COMPLETE ]|##################################################| 100%
Unlinking packages ...
[ COMPLETE ]|##################################################| 100%
Linking packages ...
[ COMPLETE ]|##################################################| 100%
However , when I try to import the package it says no module name pylev . Same thing happens with Python-levenshtein . Command used are (tried variants of his but doesn't seem to work)
import pylev
import Levenshtein
Unable to figure out what the problem is

Some modules (this is a C extension) must be compiled for the architecture you are using. See explained for your case here.
But you can always use compiled versions if they are available (as is the case for pylevenshtein) from Christoph Gohlke's website

Related

Downloading Big Packages using conda in batches

I am curious whether I can download big packages in batches using conda (like in web browsers where we can resume interrupted downloads).
I wanted to update my pytorch package but the size is too big for my limited mobile data.
The following packages will be downloaded:
package | build
---------------------------|-----------------
libuv-1.40.0 | he774522_0 255 KB
pytorch-1.8.1 |py3.7_cuda10.1_cudnn7_0 836.4 MB pytorch
torchvision-0.9.1 | py37_cu101 7.3 MB pytorch
------------------------------------------------------------
Total: 843.9 MB
The following NEW packages will be INSTALLED:
libuv pkgs/main/win-64::libuv-1.40.0-he774522_0
The following packages will be UPDATED:
pytorch 1.4.0-py3.7_cuda101_cudnn7_0 --> 1.8.1-py3.7_cuda10.1_cudnn7_0
torchvision 0.5.0-py37_cu101 --> 0.9.1-py37_cu101
No this is not possible in conda. Completely downloaded files will not be redownloaded, but files which are only partially downloaded before interruption will need to be redownloaded:
https://github.com/conda/conda/issues/800

while installing tensorflow-datasets in anaconda; packages will be SUPERSEDED by a higher-priority channel:

while installing tensorflow-datasets in anaconda, using CMD.exe Prompt of anaconda navigator, I am getting the message: packages will be SUPERSEDED by a higher-priority channel
conda install -c anaconda tensorflow-datasets
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Users\PRASHIK\anaconda3\envs\python_3_6_added / updated specs:tensorflow-datasets
The following packages will be downloaded:
package | build
---------------------------|-----------------
ca-certificates-2020.10.14 | 0 159 KB anaconda
certifi-2020.6.20 | py36_0 160 KB anaconda
dill-0.3.2 | py_0 65 KB anaconda
future-0.18.2 | py36_1 744 KB anaconda
googleapis-common-protos-1.52.0| py36h21ff451_0 75 KB anaconda
promise-2.3 | py36_0 37 KB anaconda
tensorflow-datasets-1.2.0 | py36_0 2.3 MB anaconda
tensorflow-metadata-0.14.0 | pyhe6710b0_1 165 KB anaconda
tqdm-4.50.2 | py_0 55 KB anaconda
------------------------------------------------------------
Total: 3.7 MB
The following NEW packages will be INSTALLED:
dill anaconda/noarch::dill-0.3.2-py_0
future anaconda/win-64::future-0.18.2-py36_1
googleapis-common~ anaconda/win-64::googleapis-common-protos-1.52.0-py36h21ff451_0
promise anaconda/win-64::promise-2.3-py36_0
tensorflow-datase~ anaconda/win-64::tensorflow-datasets-1.2.0-py36_0
tensorflow-metada~ anaconda/noarch::tensorflow-metadata-0.14.0-pyhe6710b0_1
tqdm anaconda/noarch::tqdm-4.50.2-py_0
The following packages will be SUPERSEDED by a higher-priority channel:
ca-certificates pkgs/main::ca-certificates2021.4.13-~-->anaconda::cacertificates2020.10.14-0
certifi pkgs/main::certifi-2020.12.5-py36haa9~ --> anaconda::certifi-2020.6.20py36_0
Proceed ([y]/n)?
Is this ok?
Does it causes any issue in future, if yes can someone suggest remedies, please.
Is this ok? Does it causes any issue in future, if yes can someone
suggest remedies, please.
It doesn't cause any issue. By default, conda prefers packages from a higher priority channel over any version from a lower priority channel. Therefore, you can now safely put channels at the bottom of your channel list to provide additional packages that are not in the default channels and still be confident that these channels will not override the core package set.
Conda collects all of the packages with the same name across all listed channels and processes them as follows:
Sorts packages from highest to lowest channel priority.
Sorts tied packages---packages with the same channel priority---from highest to lowest version number.
Sorts still-tied packages---packages with the same channel priority and same version---from highest to lowest build number.
Installs the first package on the sorted list that satisfies the installation specifications.
You can refer for a list of all the versions that are available for ca-certificates and certifi.
For more information on manage channels you can refer here

Why does conda want to update unrelated packages when I want to remove just one?

Windows 10
conda 4.9.2 (via miniconda)
I installed a single package that did not require any other dependencies to be installed anew or upgraded. Once I realised that I had installed an unsuitable version of the package, I went to remove it, and this is the screen I was presented with:
(pydata) PS C:\Users\Navneeth> conda remove xlrd
Collecting package metadata (repodata.json): done
Solving environment: |
Warning: 2 possible package resolutions (only showing differing packages):
- defaults/win-64::libtiff-4.1.0-h56a325e_1, defaults/win-64::zstd-1.4.9-h19a0ad4_0
- defaults/win-64::libtiff-4.2.0-hd0e1b90_0, defaults/win-64::zstd-1.4.5-h04227a9done
## Package Plan ##
environment location: C:\Users\Navneeth\Miniconda3\envs\pydata
removed specs:
- xlrd
The following packages will be downloaded:
package | build
---------------------------|-----------------
decorator-5.0.3 | pyhd3eb1b0_0 12 KB
importlib-metadata-3.7.3 | py38haa95532_1 31 KB
importlib_metadata-3.7.3 | hd3eb1b0_1 11 KB
ipython-7.22.0 | py38hd4e2768_0 998 KB
jupyter_client-6.1.12 | pyhd3eb1b0_0 88 KB
libtiff-4.1.0 | h56a325e_1 739 KB
nbformat-5.1.3 | pyhd3eb1b0_0 44 KB
notebook-6.3.0 | py38haa95532_0 4.4 MB
pandoc-2.12 | haa95532_0 13.2 MB
parso-0.8.2 | pyhd3eb1b0_0 69 KB
pillow-8.2.0 | py38h4fa10fc_0 671 KB
prometheus_client-0.10.0 | pyhd3eb1b0_0 46 KB
prompt-toolkit-3.0.17 | pyh06a4308_0 256 KB
terminado-0.9.4 | py38haa95532_0 26 KB
zipp-3.4.1 | pyhd3eb1b0_0 15 KB
zstd-1.4.9 | h19a0ad4_0 478 KB
------------------------------------------------------------
Total: 21.0 MB
The following packages will be REMOVED:
xlrd-2.0.1-pyhd3eb1b0_0
The following packages will be UPDATED:
decorator 4.4.2-pyhd3eb1b0_0 --> 5.0.3-pyhd3eb1b0_0
importlib-metadata pkgs/main/noarch::importlib-metadata-~ --> pkgs/main/win-64::importlib-metadata-3.7.3-py38haa95532_1
importlib_metadata 2.0.0-1 --> 3.7.3-hd3eb1b0_1
ipython 7.21.0-py38hd4e2768_0 --> 7.22.0-py38hd4e2768_0
jupyter_client 6.1.7-py_0 --> 6.1.12-pyhd3eb1b0_0
nbformat 5.1.2-pyhd3eb1b0_1 --> 5.1.3-pyhd3eb1b0_0
notebook 6.2.0-py38haa95532_0 --> 6.3.0-py38haa95532_0
pandoc 2.11-h9490d1a_0 --> 2.12-haa95532_0
parso 0.8.1-pyhd3eb1b0_0 --> 0.8.2-pyhd3eb1b0_0
pillow 8.1.2-py38h4fa10fc_0 --> 8.2.0-py38h4fa10fc_0
prometheus_client 0.9.0-pyhd3eb1b0_0 --> 0.10.0-pyhd3eb1b0_0
prompt-toolkit 3.0.8-py_0 --> 3.0.17-pyh06a4308_0
sqlite 3.33.0-h2a8f88b_0 --> 3.35.3-h2bbff1b_0
terminado 0.9.2-py38haa95532_0 --> 0.9.4-py38haa95532_0
zipp 3.4.0-pyhd3eb1b0_0 --> 3.4.1-pyhd3eb1b0_0
zstd 1.4.5-h04227a9_0 --> 1.4.9-h19a0ad4_0
The following packages will be DOWNGRADED:
libtiff 4.2.0-he0120a3_0 --> 4.1.0-h56a325e_1
Proceed ([y]/n)?
Why does conda want to update or downgrade all these other packages when the opposite wasn't done when I installed xlrd? Is there a way that I can safely remove the just xlrd. (I hear using --force is risky.)
Asymmetry
Conda re-solves when removing. When installing, Conda first attempts a frozen solve, which amounts to keeping all installed packages fixed and just searching for a version of the requested package(s) that are compatible. In this specific case, xlrd (v2.1.0) is a noarch with only a python>=3.6 constraint. So this installs in this frozen solve pass.
The constraint xlrd will also be added to the explicit specifications.1
When removing, Conda will first remove the constraint, and then re-solves the environment with the new set of explicit specifications. It is in this solve that Conda identifies that newer versions of packages and then proposes updating then.
So, the asymmetry is that the frozen solve explicitly avoids checking for any new packages, but the removal will trigger such a check. There is not currently a way to avoid this without bypassing dependency checking.
Mamba
Actually, mamba, a compiled (fast!) drop-in replacement for conda, will remove only the specified package if it doesn't have anything depending on it. That is its default behavior in my testing.
Addendum: Still Some Unexplained Behavior
I replicated your experience by first creating an environment with two specs:
name: foo
channels:
- conda-forge
dependencies:
- python=3.8.0
- pip=20
To simulate this being an old environment, I went into the envs/foo/conda-meta/history and changed2 the line
# update specs: ['pip=20', 'python=3.8.0']
to
# update specs: ['python=3.8']
Subsequently running conda install xlrd does as expected. Then conda remove xlrd gives a somewhat odd result:
## Package Plan ##
environment location: /opt/conda/envs/foo
removed specs:
- xlrd
The following packages will be downloaded:
package | build
---------------------------|-----------------
pip-21.1.1 | pyhd8ed1ab_0 1.1 MB conda-forge
------------------------------------------------------------
Total: 1.1 MB
The following packages will be REMOVED:
xlrd-2.0.1-pyhd8ed1ab_3
The following packages will be UPDATED:
pip 20.3.4-pyhd8ed1ab_0 --> 21.1.1-pyhd8ed1ab_0
Proceed ([y]/n)?
This effectively replicates OP result, however, the additional oddity here is that the python package is not suggested to be updated, even though I had intentionally loosened its constraint from 3.8.0 to 3.8. It appears that only packages not in the explicit specifications are subject to updating during package removal.
[1] The explicit specifications are the internally maintained records that Conda keeps of every constraint a user has explicitly specified. One can view the current explicit specifications of an environment with conda env export --from-history. The raw internal records can be found at yourenv/conda-meta/history.
[2] Not a recommended practice!

Python Matplotlib: Issue on updating matplotlib to 3.1.2 on windows

Following the release of Matplotlib to the 3.1.2 version I am having issues updating my package version.
I tried:
conda install -c conda-forge matplotlib=3.1.2 in Jupyter notebook (Without success, the code kept running for 20 mins before I interrupted); in the Anaconda prompt with the following failed result:
(base) C:\Users\Adrien>conda install -c conda-forge matplotlib=3.1.2
Collecting package metadata (current_repodata.json): done Solving
environment: failed with initial frozen solve. Retrying with flexible
solve. Collecting package metadata (repodata.json): done Solving
environment: failed with initial frozen solve. Retrying with flexible
solve. Solving environment: | Found conflicts! Looking for
incompatible packages. This can take several minutes. Press CTRL-C to
abort. failed
conda update matplotlib with the following result:
(base) C:\Users\Adrien>conda update matplotlib Collecting package
metadata (current_repodata.json): done Solving environment: /
Updating matplotlib is constricted by
anaconda -> requires matplotlib==3.1.1=py37hc8f65d3_0
If you are sure you want an update of your package either try conda
update --all or install a specific version of the package you want
using conda install <pkg>=<version>
done
Package Plan
environment location: C:\Users\Adrien\Anaconda3
added / updated specs:
- matplotlib
The following packages will be downloaded:
package | build
---------------------------|-----------------
backports.functools_lru_cache-1.6.1| py_0 11 KB
conda-4.8.3 | py37_0 2.8 MB
future-0.18.2 | py37_0 656 KB
------------------------------------------------------------
Total: 3.5 MB
The following packages will be UPDATED:
backports.functoo~ 1.5-py_2 -->
1.6.1-py_0 conda 4.8.2-py37_0 --> 4.8.3-py37_0 future 0.17.1-py37_0 --> 0.18.2-py37_0
Proceed ([y]/n)? y
Downloading and Extracting Packages conda-4.8.3 | 2.8 MB |
################################################################## | 100% future-0.18.2 | 656 KB |
################################################################## | 100% backports.functools_ | 11 KB |
################################################################## | 100% Preparing transaction: done Verifying transaction: done
Executing transaction: done
(base) C:\Users\Adrien>import matplotlib 'import' is not recognized as
an internal or external command, operable program or batch file.
And after restarting the system and Jupyter as you guess:
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
matplotlib: 3.1.1
Any idea on what could be the next step ?
Many thanks in advance
Either you do:
conda update --all
or you try:
conda install matplotlib=3.1.2

Installing OpenCV with Conda

Installing packages to start running some code is perhaps the hardest part of my job.
Anways, I tried installing opencv for use in anaconda python 3.6 environment. And I get the error:
conda install -c conda-forge opencv
Fetching package metadata ...........
Solving package specifications: ..........
Package plan for installation in environment C:\Program Files\Anaconda3\envs\py36:
The following packages will be downloaded:
package | build
---------------------------|-----------------
libwebp-0.5.2 | vc14_7 1.1 MB conda-forge
opencv-3.2.0 | np112py36_204 92.0 MB conda-forge
------------------------------------------------------------
Total: 93.1 MB
The following NEW packages will be INSTALLED:
libwebp: 0.5.2-vc14_7 conda-forge [vc14]
opencv: 3.2.0-np112py36_204 conda-forge
Proceed ([y]/n)? y
Fetching packages ...
libwebp-0.5.2- 100% |###############################| Time: 0:00:05 213.41 kB/s
opencv-3.2.0-n 100% |###############################| Time: 0:00:48 1.97 MB/s
Extracting packages ...
[ COMPLETE ]|##################################################| 100%
Linking packages ...
PaddingError: Placeholder of length '34' too short in package conda-forge::opencv-3.2.0-np112py36_204.
The package must be rebuilt with conda-build > 2.0.
I am on a Windows System. I do not understand the error and searching isn't helping.
Any comments or suggestions to resolve the error are welcome.
For the record, OpenCV installs fine with pip.
Tested on Windows 10 with Miniconda and Python 3.6:
> pip search opencv
...
opencv-python
...
> pip install opencv-python
Tells me Requirement already satisfied.
To make sure it was correctly installed, run:
> python
>>> import cv2
>>>
Go to the root conda environment.
And do conda update conda.
Then just import cv2 and use it.

Categories

Resources