python : request dependency idna failed "ImportError: No module named idna" - python-3.x

I am using the request module in python, which has inda as a dependency.
I am keeping idna module inside request module but still it is not able to detect the inda module.
"/mnt/yarn/usercache/root/appcache/application_1522067995292_0020/container_1522067995292_0020_01_000001/slackclient.zip/slackclient/requests/packages.py", line 7, in
ImportError: No module named idna

I had the same issue and strangely installing idna worked for me
$ pip install idna

Use requirements.txt avoid these dependency mix-ups.
Firstly, when your code is working all good, do this
$ pip freeze > requirements.txt
This stores all the installed packages into the text file.
Now use requirements.txt file to install all modules wherever it runs hereafter
$ pip install -r requirements.txt
If needed, can upgrade your modules and check everything working cool and then update requirements.txt again.
When not mentioning the versions, usually the latest versions of the packages are fetched and installed. Some of the updates from dependency's dependency(inception) package might break.

Related

Installing requirements.txt into virtual environment

I have a directory with scripts *.py that I need to compile on another computer that includes different versions of modules. I opened the terminal in that directory and have created requirements:
pip freeze > requirements.txt
Then I created a vertual environment and tried to installed packages from requirements.txt
virtualenv compilation
source compilation/bin/activate
python3.6 -m pip install -r requirements.txt
It ended with this:
ERROR: Cannot install babel==2.7.0, gitsome==0.8.4 and pytz==2021.1 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested pytz==2021.1
babel 2.7.0 depends on pytz>=2015.7
gitsome 0.8.4 depends on pytz<2017.0 and >=2016.3
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
Why is there a conflict when these packages work in non-virtual python3.6, please? What to do with that, please?
After babel and gitsome upgrade
ERROR: Cannot install babel==2.7.0, gitsome==0.8.4, pandas==1.1.5 and pytz==2016.10 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested pytz==2016.10
babel 2.7.0 depends on pytz>=2015.7
gitsome 0.8.4 depends on pytz<2017.0 and >=2016.3
pandas 1.1.5 depends on pytz>=2017.2
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
Downgrading pytz
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pandas 1.1.5 requires pytz>=2017.2, but you have pytz 2015.7 which is incompatible.
gitsome 0.8.4 requires pytz<2017.0,>=2016.3, but you have pytz 2015.7 which is incompatible.
Successfully installed pytz-2016.10
Removed build tracker: '/tmp/pip-req-tracker-8c5_ezeo'
You may want to try downgrading pytz
pip install -Iv pytz==2017.0
or upgrading babel and gitsome
sudo pip install babel --upgrade
sudo pip install gitsome --upgrade

does pip reinstall libraries everytime when creating a virtual environment?

I know it might sound stupid, but I genuinely tried my best to understand if pip installs packages from the internet every single time or does it just clone and use the already globally installed packages when I am creating a venv?
What exactly is the difference between pip install and pip download?
What does it mean by
Collecting package <package_name>...
Using cached <package_name>...
and
Downloading <package_name>
Can someone help me out...
pip download replaces the --download option to pip install, which is now deprecated and was removed in pip 10.
pip download does the same resolution and downloading as pip install, but instead of installing the dependencies, it collects the downloaded distributions into the directory provided (defaulting to the current directory). This directory can later be passed as the value to pip install --find-links to facilitate offline or locked down package installation.
The idea behind the pip cache is simple, when you install a Python package using pip for the first time, it gets saved on the cache. If you try to download/install the same version of the package on a second time, pip will just use the local cached copy instead of retrieving it from the remote register .
If you plan to use the same version of the package in another project then using cached packages is much faster.
But if pip installs the cached version of the package and you want to upgrade to the newest version of the package then you can simply upgrade by: pip install <package_name> --upgrade

When i install a new version of python i need to install the packages again

When i install (upgrade) to the new version of Python (3.8.1 in this case) i need to install the packages again such as:
requests
pandas
sklearn
matplotlib
etc...
(i have to do pip install moduleName for each one).
This is not the first time such has happenned.
How does one execute the installation of a new version without having to re-install the packages ?
Before you upgrade in a terminal run,
pip freeze > requirements.txt
This will store the names and versions of all your downloaded modules in a requirements.txt file in the current directory. Then after your new version of python is downloaded cd back into that directory and run
pip install -r requirements.txt
This will re-install all of your modules without having to enter them in one by one.

PIP UPGRADE - Trouble with versions in personal setup package

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

setuptools, use package on local system instead of getting it from PyPI

There is an open-source python package that I want to work on (toga-android). To test the code I write, I have to be able to build my own project that has said open-source package as a dependency. My project has to be built with setuptools, so I need setuptools to fulfill the dependency using my version of the package, and not get the package from PyPI.
The problem is that setuptools always gets the package from PyPI.
Whenever I build with setuptools I see:
Collecting toga-android==0.3.0.dev8
Downloading https://files.pythonhosted.org/packages/92/fe/348a39e2e0bbcac2d3ed511dd2b62943b488e7dcb8097c437416caf1c179/toga_android-0.3.0.dev8-py3-none-any.whl
or
Collecting toga-android==0.3.0.dev8
Using cached https://files.pythonhosted.org/packages/92/fe/348a39e2e0bbcac2d3ed511dd2b62943b488e7dcb8097c437416caf1c179/toga_android-0.3.0.dev8-py3-none-any.whl
Clearly it is getting the package from PyPI or using a cached version from it.
I have installed my version using pip install -e . , and that has no effect. I have also tried including the package's source in my project's directory with setup.py. Setuptools apparently includes this code because syntax errors there make the build fail, but it doesn't recognize that it can satisfy the dependency. It still gets the package from PyPI and any modules imported from the package are the PyPI versions.
How can I use of custom version of a package that is also in PyPI as a setuptools dependency?
Steps to reproduce:
pip install briefcase (using or not using virtualenv does not matter)
git clone https://github.com/pybee/toga.git
cd ~/toga/src/core; sudo pip install -e .
cd ~/toga/src/android/; sudo pip install -e .
cd ~/toga/examples/tutorial0
python setup.py android
The output will show that an older version of toga-android is downloaded even though it was already installed with pip.

Resources