PIP UPGRADE - Trouble with versions in personal setup package - python-3.x

I'm working on my first python package, so I'm new with all this.
I have my own setup package which I install through pip install git+<URL>.git.
When I try to upgrade it with the --upgrade flag, it always get reinstalled, even if I haven't changed the version in my setup.py file.
Does anyone know why this is happening? o maybe have a better approach to this?
I have made my research before asking, but I think this is a very specific problem.
I have tried in a venv and out.
python 3.7, pip 19.2, setuptools 40.8
# setup.py
from test import __version__
from setuptools import find_packages, setup
setup(
name="test",
version=__version__,
packages=find_packages(),
)
I expect to get something similar to:
Requirement already up-to-date: test in ./<cwd>/.venv/lib/python3.7/site-packages (0.0.1)
but instead I get this:
Installing collected packages: test
Found existing installation: test 0.0.1
Uninstalling test-0.0.1:
Successfully uninstalled test-0.0.1
Running setup.py install for test ... done
Successfully installed test-0.0.1

Reading the documentation it seems like the expected behaviour to me.
Note that if a satisfactory version of the package is already installed, the VCS source will not overwrite it without an --upgrade flag.
Read a somewhat related discussion here:
https://github.com/pypa/pip/issues/2837
Looks like pip does upgrades in a much more binary fashion when VCS is involved. It seems to always upgrade when --upgrade is set and never when it's not set.
You could try the work-around that is suggested in this discussion, but be aware of its side effects (for example, you will have a full clone of the git repository on your file system):
pip install --editable --upgrade git://somewhere/something.git

Related

No local packages or working download links found for SIP, in the Appveyor Windows Containers, when testing python 3.5

For continuous integrations, we test our scripts for Windows OS with appveyor, as usual after each push in GitHub. The tests are launched for python 3.5, 3.6 and 3.7. For 3.6 and 3.7 all is working fine. For 3.5, the test falls due to no SIP package found:
searching for SIP
Reading https://pypi.python.org/simple/SIP/
No local packages or working download links found for SIP
error: Could not find suitable distribution for Requirement.parse('SIP')
Command exited with code 1
It is strange because:
For python 3.6 the return is:
Searching for SIP
Reading https://pypi.org/simple/SIP/
Downloading https://files.pythonhosted.org/packages/7a/49/67cc7955baf2ec5b67e141da2ab2a436cbf0f8d7c9fcab54e35df21d056b/sip-4.19.8-cp36-none-win32.whl#sha256=74da4ddd20c5b35c19cda753ce1e8e1f71616931391caeac2de7a1715945c679
Best match: sip 4.19.8
Processing sip-4.19.8-cp36-none-win32.whl
Installing sip-4.19.8-cp36-none-win32.whl to c:\python36\lib\site-packages
Adding sip 4.19.8 to easy-install.pth file
For python 3.7 the return is:
Searching for SIP
Reading https://pypi.org/simple/SIP/
Downloading https://files.pythonhosted.org/packages/89/34/056db01926839dd05f80a08a579ee2f4f6625913b0620580ee580fa05fbf/sip-4.19.8-cp37-none-win32.whl#sha256=1bb10aac55bd5ab0e2ee74b3047aa2016cfa7932077c73f602a6f6541af8cd51
Best match: sip 4.19.8
Processing sip-4.19.8-cp37-none-win32.whl
Installing sip-4.19.8-cp37-none-win32.whl to c:\python37\lib\site-packages
Adding sip 4.19.8 to easy-install.pth file
So for python 3.5 we can think that the good target is sip-4.19.8-cp35-none-win32.whl, and by inspecting https://pypi.python.org/simple/SIP/ it seems that it is existing!
It seems that the issues comes from a difference in processing between the pip install ... command and the setup (install_requires=...) method used with the python setup.py install command.
Since I edited the appveyor.yml file to install all the necessaries packages with pip just before the python setup.py install installation command, it is working fine.
It's quick and dirty (I am sure that it is possible to do more elegant and skilled by configuring better), but it works!
The setup.py file.
The info.py file.
The former appveyor.yml file.
The new appveyor.yml file.
EDIT:
May be quicker and cleaner. Starting from the difference observed beetween pip and setuptools I observed that the build started with a very old setuptools version:
pip list
Package Version
---------- -------
pip 19.1
setuptools 28.8.0
virtualenv 15.0.1
So I just made an update of setuptools:
pip install --upgrade -vv setuptools
and now all is working fine, without adding twice the requested repositories in install_requires.
The former appveyor.yml file.
The new appveyor.yml file.

python install wheel leads to import error

I'd like to make a wheel binary distribution, intstall it and then import it in python. My steps are
I first create the wheel: python ./my_package/setup.py bdist_wheel
I install the wheel: pip install ./dist/*.whl
I try to import the package: python -c"import my_package"
This leads to the error:
ImportError: No module named 'my_package'
Also, when I do pip list, the my_package is listed.
However, when I run which my_packge, nothing is shown.
When I run pip install ./my_package/ everything works as expected.
How would I correctly build and install a wheel?
python version 3.5
pip version 10.1
wheel version 0.31.1
UPDATE:
When I look at the files inside my_package-1.0.0.dist-info, there is an unexpected entry in top_level.txt. It is the name of the folder where I ran
python ./my_package/setup.py bdist_wheel in. I believe my setup.py is broken.
UPDATE WITH REGARDS TO ACCEPTED ANSWER:
I accepted the answer below. Yet, I think it is better to simply cd into the package directory. Changing to a different directory as suggested below leads to unexpected behavior when using the -d flag, i.e. the target directory where to save the wheel. This would be relative to the directory specified in the setup.py file.
I had the very same error, but it was due to my setup.py not specifying the entry "packages=setuptools.find_packages()".
Everythings builds nicely without that but you can't import anything even though pip shows it to be installed.
If you need to execute the setup script from another directory, ensure you are entering the project dir in the script.
from setuptools import setup
root = os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))
os.chdir(root)
# or using pathlib (Python>=3.4):
import patlib
root = pathlib.Path(__file__).parent
os.chdir(str(root))
setup(...)
In my case, in order to solve it I just had to upgrade pip (since Docker installed pip 9).
python3 -m pip install --upgrade pip
I have experienced the same situation, maybe not for the same reason, here just for reference.
The package name should not contain the dash "-", there's no error pop out, but after installing your wheel, though it is shown in pip list, you can't find that package.
/src/your-package-name # should not
/src/your_package_name # should like this
In the setup.py, you can use the name with dash "-" without limitation:
setuptools.setup(
name="instrument-lab",
...

How to install library

I am a little bit confused....
I installed anaconda on my computer (I have windows 10).
Normally, when I want to install a package I simply do "pip install package_name" or "conda install package_name" and it is done.
First question: what is the difference between pip and conda?
Now I tried to install xgboost and it was really complicated I tried lot of things nothings worked until I install something called miniconda.
There it works but now, when I do "conda install package_name" it install it in miniconda3/lib/site _package and I have to copy/paste it in Anaconda3/lib/site_package if I want it to work.
Second question: how can I ask to the computer that "conda install
package_name" install it directly in anaconda3 and not miniconda3?
Finally I tried to install the package "surprise" for recommended systems. Both "pip install" or "conda install" failed.
I went in github and got the file "surprise" from https://github.com/NicolasHug/Surprise
I tried to copy it in Anaconda3/lib/site_package but it doesn't work.
When I do from surprise import Reader I did not get the error "no module name surprise" anymore but I get "cannot import name 'Reader'"
Last question: how can I make it work? I think I have to build it but
I do not now how...
Thank you in advance for anyone that can explain all this for me :-)
Similarly to you, I had issues installing the surprise package.
I tried both pip install surprise and conda install surprise unsuccessfully.
conda install -c conda-forge scikit-surprise
conda install -c conda-forge/label/gcc7 scikit-surprise
conda install -c conda-forge/label/cf201901 scikit-surprise
I found those on the anconda website and the first one worked for me.
Hopefully this would help you as well
pip vs conda
pip is a package manager that facilitates installation, upgrade,
and uninstallation of python packages. It also works with virtual python environments.
conda is a package manager for any software (installation, upgrade and uninstallation).
It also works with virtual system environments.
Conda is a packaging tool and installr that aims to do more than what pip does;
handle library dependencies outside of the Python packages as well as the Python packages themselves.
Conda also creates a virtual environment, like virtualenv does.
For more see here
Anaconda vs miniconda
The open source version of Anaconda is an easy-to-install
high performance Python and R distribution with a package manager,
environment manager and collection of 720+ open source packages.
It also comes with the options to install RStudio.
The "lite" version of Anaconda without the collection of 720 packages.
The downside is that you need to type in command line commands,
"conda install PACKAGENAME"
And Last
To install this package with conda run:
conda install -c anaconda py-xgboost=0.60
Update for surprise
The easiest way is to use pip (you'll need numpy):
$ pip install numpy
$ pip install scikit-surprise
Or you can clone the repo and build the source (you'll need Cython and numpy):
$ git clone https://github.com/NicolasHug/surprise.git
$ python setup.py install

Error installing urllib3

I am using the command pip install urllib3, the error trace I am getting is as below.
Which pip version do you use?
Try first to run the command pip install --upgrade pip
After that, when your pip version is up-to-date try to install the urllib3.
EDIT:
Alternatively, you can grab the latest source code from GitHub:
git clone git://github.com/shazow/urllib3.git
python setup.py install
Without seeing the full traceback, this looks like your computer cannot resolve the addresses for pypi.python.org or pypi.org (I dont' know what version of pip you're using).
This could be because of a proxy issue or some other internet connectivity issue. There is literally no way for someone to help you debug this without more information.
Finally
pip install urllib3 version=2.4.0
Does not do what you think. What you told pip to do was install urllib3 and install a package named version. If you want a specific version you need to write
pip install urllib3===1.4.0
Or whatever version you need.

Why isn't pip v7.1.0 caching wheels?

I'm running pip v7.1.0 (latest as of this writing) and running into an issue where it's not caching at all.
Here is how I'm installing Django -
pip install --cache-dir=d:\pipcache django
The package installs successfully, but there is nothing cached. I've read the latest documentation and checked my AppData/Local path and it's empty. What I'm looking to do is have everything I install through pip cached, so all subsequent virtual environment creations are quick.
EDIT
Turns out that pip won't cache packages that have wheel files. I tried forcing pip to build the source --no-binary=django to no avail.
Having said that, how can I force pip to cache my requirements whether the maintainers have provided wheels or not?
Based on my understanding of pip, this should be the new default. Not sure why it isn't working, though.
Alternatively, I have to do this -
pip wheel --wheel-dir="D:/"-r reqs
pip install --no-index --find-links="D:/" -r reqs
Is this within a venv? If so, you may have to explicitly install wheel into the venv using pip install wheel. After that, pip should start automatically building/caching your wheels.

Resources