install "sub package" Jupyter Notebook - pip

I am struggling to install packages, and "sub-packages" in Jupyter Notebook; I suspect I am missing some of the basic concepts around installing packages.
I understand that to install a package within the notebook I use
! pip install --user <package>
What I don't understand is how to install a "sub-package" (feel free to advise what the correct terminology is) such as below.
from nltk.tagger import *
Here is the original script that this comes from:
If i try :
!pip install nltk.tagger
I get the following error information / error
Collecting nltk.tagger
Could not find a version that satisfies the requirement nltk.tagger (from versions: ) No matching distribution found for nltk.tagger
So my first question is. How do I install this nltk.tagger subpackage? Also if tagger is a sub-package of NLTK, how come it isn't installed when I do a pip install NLTK?
Although the error mentions a version, searching online I can't find a reference even to the subpackage "tagger". Any advice or links explaining this would be appreciated.

if you pip inslall nltk, the subpackage nltk.tagger, and other dependencies will be installed too.
This is generally true for all packages.

Related

Pip suddenly cant find or install any package

Suddenly pip cant install or find any package, it cant even figure out its own version.
I reinstalled python multiple times, i have the latest version of python 3 and pip. I also tried to clear pip cache. Nothing works, this is really annoying...
Errors:
>pip install redblacktree
ERROR: Could not find a version that satisfies the requirement redblacktree (from versions: none)
ERROR: No matching distribution found for redblacktree
WARNING: There was an error checking the latest version of pip
>pip config list
freeze.user='yes'
global.index-url='http://pypi.org/simple'
global.trusted-host='pypi.org'
install.user='yes'
list.user='yes'
uninstall.user='yes'
I fixed it by locating the pip.ini config file and removing the line index-url = http://pypi.org/simple

pip install is looking for required dependency within the package

I'm build up my package with setup.py, in which it has a install_requires=get_requirements('requirements.txt'), and in the requirements.txt, the first required dependency is bottle==0.12.18.
Then I ran
python setup.py sdist
twine upload --repository testpypi dist/*
After uploading succeeded, I installed with pip install -i https://test.pypi.org/simple/ my_package==version_num which gives me the error
Collecting bottle==0.12.18 (from mypakage==version_num)
Could not find a version that satisfies the requirement bottle==0.12.18 (from mypakage==version_num) (from versions: )
No matching distribution found for bottle==0.12.18 (from mypakage==version_num)
Looks like it's looking for the dependency within my package, which will definitely fail. This error suddenly started happening and I've never seen this before. Do you have any idea why it's happening and how can I make it look for dependency in a way like pip install -r requirements?

Pip install package not from pypi, whose name is the same as one in pypi ( + with dependencies from pypi )

I have a python package, hosted on azure (vsts), not on pypi, whose dependencies are python packages that live in pypi.
My package has the same name as a package that lives on pypi, I discovered.
Is there a way of installing my package with pip, specifying that my package must be searched on vsts before, while the dependencies can be grabbed from pypi?
If I use the --index-url option:
pip install <my-package> --index-url https://<my-package>:<PAT>#<url>/<proj>/_packaging/<my-package>/pypi/simple/
pip is able to locate my package, tries to install it, but it fails to install any dependency (because it searches for all of them in the same url, which is wrong because I am not hosting, say, my own version of numpy or other packages on vsts).
(This is the problem: pip install producing "Could not find a version that satisfies the requirement" )
If instead I use the --extra-index-url option:
pip install <my-package> --extra-index-url https://<my-package>:<PAT>#<url>/<proj>/_packaging/<my-package>/pypi/simple/
all the dependencies are found, but the problem is that this does not install my package, but the package with the same name that lives in pypi!
Even if --extra-index-url is there, it seems that pypi is given priority, and therefore my package that would be found at the url I specified is shadowed and doesn't get correctly found and installed.
Is there a way to, say, tell pip that it should give priority to my --extra-index-url? Or to give pip an --index-url which should only be valid for one package but not for its dependencies?
You need index URL pointing to VSTS and extra URL to PyPI:
pip install --index-url=https://<my-package>:<PAT>#<url>/<proj>/_packaging/<my-package>/pypi/simple/ --extra-index-url=https://pypi.org/simple/ <my-package>

Cannot import GLPK in Anaconda

I searched a lot an answer to my problem but wasn't able to find a fix.
I'm running anaconda.
I installed glpk with from conda-forge with the command:
conda install -c conda-forge glpk
The installation worked fine but then in my notebook, I've got an error message when I try to import the module :
ModuleNotFoundError: No module named 'glpk'
I had no problem to install and import other packages.
Any ideas?
Thank you very much in advance
The files installed by
conda install -c conda-forge glpk
can be found at https://anaconda.org/conda-forge/glpk/files. Looking at the archives only the GLPK C library is installed and no Python binding or package.
One of the packages that can call the GLPK library from Python is Pulp (https://anaconda.org/conda-forge/pulp).
I'm conda/windows user. I never could import it directly, but based on this SO answer I could make work a library that consume it (pypsa)
Basically, download the library (is in sourceforge) and add it to windows system path
Hope this help to somebody googling this issue. Bests

Installing specific versions of pyproj from github

I have been trying to install obspy and have been running into a lot of problems. I want to install obspy which has a dependency on pyproj. But apparently obspy only works with pyproj 1.9.5.1, which I tried installing using pip (pip3 install pyproj==1.9.5.1), but only got the errors like-
_proj.c:7488:13: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘exc_traceback’; did you mean ‘curexc_traceback’?
Digging deeper I found that it might be a Cython problem, and installing pyproj directly from github might help, because it would apparently make Cython recompile all the necessary files. Something along the lines of -
pip3 install git+https://github.com/jswhit/pyproj.git
However this one gives the error -
ERROR: Minimum supported proj version is 6.2.0, installed version is 5.2.0.
I di try installing a higher version of libproj-dev (sudo apt install libproj-dev=6.2.0) however it shows that there is no candidate for 6.2.0. I tried downloading the deb file and installing from that using -
sudo apt-get install ~/Downloads/libproj-dev_6.2.0-1_amd64.deb
which just leads to the error -
The following packages have unmet dependencies:
libproj-dev : Depends: libproj15 (= 6.2.0-1) but it is not installable
E: Unable to correct problems, you have held broken packages.
But I think this is not the right way to install for me anyway, since I need a specific version. Hence I tried installing directly from the tarball of the release -
pip3 install https://github.com/pyproj4/pyproj/archive/v1.9.5.1rel.tar.gz
Which leads to the first error I had, evidently due to Cython.
With errors on everything I tried to do to fix this, I am not sure what even is relevant to my problem now.
Any help is appreciated, and if this site is not the correct place for this question, please help me migrate it to its proper destination.
I am on Ubuntu 18.10.
The problem is, that Cython-generated c-files don't work for Python-3.7 if generated with Cython versions up to 0.27.3 (at least): The setup.py of pyproj (at least in the version 1.9.5.1) doesn't regenerate the_proj.c, which is generated with Cython 0.23.2 and thus the installation cannot succeed.
You have the following options:
stay on Python3.6 where everything works out of the box.
regenerate _proj.c with a current Cython-version.
For the second option:
download and unzip your prefered version from https://github.com/pyproj4/pyproj/releases/tag/v1.9.5.1rel and switch to the created folder pyproj-1.9.5.1rel.
check, that the cython-version is >=0.27.3. via cython --version.
regenerate the _proj.c file via cython -3 _proj.pyx (_proj.pyx looks like Python3-code, but also language_level=2 (i.e. cython -2 _proj.pyx) will probably work.
install running pip install .
pyproj 1.9.5.1 was release at Jan 7, 2016. At that time, the latest version Python was 3.5. In my tests. pyproj 1.9.5.1 failed to be installed on Python 3.7.4, but succeeded on Python 3.5.7.
You need to create a environment with Python 3.5 by pyenv or conda.
References
pyproj 1.9.5.1 release
Python release history

Resources