Python-- cannot find pip.ini - python

I'm not able to get PIP to install python-imaging-tk. I get the following error:
pip-could-not-find-any-downloads-that-satisfy-the-requirement
Some other users have posted about this before, and the problem seems to be that my pip.ini file is looking at http://pypi.python.org/simple/ rather than https://pypi.python.org/simple/ . All I need to do is edit the url in pip.ini, but I can't find it. I've tried:
C:\Users\jon\pip ...and... C:\Users\jon\AppData\Local\pip
Where should I look for the .ini file?

the easiest way to locate the folder is by running the following command in the cmd.
pip config -v list
That will give you the paths that pip is searching in to find the config file.
It is possible that there is no pip.ini file in there. Then you have to create it.

As https://pip.pypa.io/en/latest/user_guide.html explains:
On Unix the default configuration file is: $HOME/.config/pip/pip.conf which respects the XDG_CONFIG_HOME environment variable.
On Mac OS X the configuration file is $HOME/Library/Application Support/pip/pip.conf.
On Windows the configuration file is %APPDATA%\pip\pip.ini.
Looks like you're on Windows, so just
echo %AppData%
at a command prompt, and that should tell you what you need to know.

Related

How to create an environment from a .yml file

I have a .yml file that I would like to create a python environment with called icesattest.yml It is in my downloads folder. When I run the following command in the Anaconda Prompt:
conda env create -f icesattest.yml
I get the following error:
EnvironmentFileNotFound: 'C:\Users\scox4\icesattest.yml' file not found
How do I tell the Anaconda prompt to look for the .yml at C:\Users\scox4\downloads\icesattest.yml? Or, how do I move the .yml file to this path so it is read? I tried to drag and drop icesattest.yml to the My PC sidebar on file explorer but it wouldn't let me move it there. I know this is a really silly mistake but I am a complete novice so any simply advice would help!
I searched and found the command that is used to create environments from .yml files so I copy pasted it as so but it failed. I changed the command to match the icesattest.yml file and it still did not work.
The way I typically handle this is via the env update command. I've found it to be a bit more robust when it comes to working with environment files.
conda env update -n <name of virtual environment> -f environment.yml
This command works both with existing environments and with new environments.
I should mention that I typically work with Linux and not Windows, so I can only guarantee that this will work well with unix systems. I'd recommend you check out something like WSL if you can, as working with Linux is typically a lot easier than Windows once you get the hang of it.
If you want to read more about conda environments: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#updating-an-environment

Library is not installed on PATH - How can I install on path?

I am running this notebook in my managed notebooks environment on Google Cloud and I'm getting the following error when trying to install the packages: "WARNING: The script google-oauthlib-tool is installed in '/home/jupyter/.local/bin' which is not on PATH.
Consider adding this directory to PATH."
Here is the python code that I'm trying to run for reference. https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/model_monitoring/model_monitoring.ipynb
Any suggestions on how I can update the package installation so it is on path and resolve the error? I'm currently working on GCP user-managed notebooks on a Mac.
Thanks so much for any tips!
RE
Open up your shell config file (likely .zshrc because the default shell on Mac is now zsh and that's the name of the zsh config file) located at your home directory in a text editor (TextEdit, etc) and add the path to the executable.
Like this:
Open the file:
open -e ~/.zshrc
Edit the file:
Add this line at the top (may vary, check the documentation):
export PATH="/home/jupyter/.local/bin"
That may not work, try this:
export PATH="$PATH:/home/jupyter/.local/bin"
Your best bet is to read the package documentation.
After saving the config file, run source ~/.zshrc and replace .zshrc with the config file name if it's different OR open a new terminal tab.
What this does is tells the shell that the command exists and where to find it.

Unsure whether pip paths are correct

I use pip to install packages. Recently, I played around with pip and virtualenv and may have unintentionally messed up things in the process. When I check pip paths, I get the following:
pip -V # pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
pip3 -V # pip 20.2b1 from /Library/Python/2.7/site-packages/pip-20.2b1-py2.7.egg/pip (python 2.7)
However, I am unsure why both pip and pip3 path to Python 2.7. Why is this the case? Does this mean that the pip I have is not compatible with Python 3.7 and if so how do I fix this?
I think you may have changed the Python pip installation path within your virtualenv
https://pip.pypa.io/en/stable/user_guide/#config-file
There is a section here that explains how you can work around your installation path for virtualenv
pip allows you to set all command line option defaults in a standard
ini style config file.
The names and locations of the configuration files vary slightly
across platforms. You may have per-user, per-virtualenv or site-wide
(shared amongst all users) configuration:
Per-user:
On Unix the default configuration file is: $HOME/.config/pip/pip.conf
which respects the XDG_CONFIG_HOME environment variable.
On macOS the configuration file is $HOME/Library/Application Support/pip/pip.conf
if directory $HOME/Library/Application Support/pip exists else
$HOME/.config/pip/pip.conf.
On Windows the configuration file is %APPDATA%\pip\pip.ini.
There are also a legacy per-user configuration file which is also
respected, these are located at:
On Unix and macOS the configuration file is: $HOME/.pip/pip.conf
On Windows the configuration file is: %HOME%\pip\pip.ini
You can set a custom path location for this config file using the
environment variable PIP_CONFIG_FILE.
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
Site-wide:
On Unix the file may be located in /etc/pip.conf. Alternatively it may
be in a “pip” subdirectory of any of the paths set in the environment
variable XDG_CONFIG_DIRS (if it exists), for example
/etc/xdg/pip/pip.conf.
On macOS the file is: /Library/Application Support/pip/pip.conf
On Windows XP the file is: C:\Documents and Settings\All Users\Application Data\pip\pip.ini
On Windows 7 and later the file is hidden, but writeable at
C:\ProgramData\pip\pip.ini
Site-wide configuration is not supported on Windows Vista
If multiple configuration files are found by pip then they are
combined in the following order:
The site-wide file is read
The per-user file is read
The virtualenv-specific file is read
Each file read overrides any values read from previous files, so if
the global timeout is specified in both the site-wide file and the
per-user file then the latter value will be used.
You will have to edit a config file in pip directory and change the target to your Python 37 site-packages location
You may have to create the pip.ini file when you find your pip directory. Within your pip.ini or pip.config you will then need to put (assuming your on windows) something like
[global]
target = Target directory

How to unzip .rar file with Python and patoolib

I need uncompress .rar file in Google Colab with Python3. First I tried to do localy in MacOS.
I have installed Patoolib package:
pip install patool
and unrar to unzip .rar files
brew install unrar
Then, In my python script I do:
import patoolib
patoolib.extract_archive("data_2/Peliculas.rar", outdir="/data_2")
and I get the following error :
PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z),
I need to configure Patool to use unrar but there is no documentation available. Somebody knows how to solve this error?
My issue was solved by simply adding my Winrar directory to my Path (in system environment variables). Made the horrible mistake of assuming it was set up by default (because why wouldn't it, it's already on the contextual menus right?), but that was not the case.
Hope this helps whoever reads this

Installing a python package in a desired folder

I have downloaded a python package to install, on my ubuntu machine. The package has already a setup.py file to use, but I want to change the default python installation address to something else, for this package specifically (and not for good). So what I tried is:
First in the terminal, I export that address of the new folder:
export PYTHONPATH=${PYTHONPATH}:${HOME}/Documents/testfolder/lib/python2.7/site-packages
Then I add this exported address as prefix to the installation command:
python setup.py install --prefix=~/Documents/testfolder
The installation goes through. Now to make python always look for this new path as well (next to the default installation path), I export the address in bashrc file:
export PYTHONPATH="${PYTHONPATH}:~/Documents/testfolder/lib/python2.7/site-packages"
But now whenever I open a terminal and try to import the installed package, it cannot see ("no module named..."). Only when I open a terminal in the folder where I had the installation files (namely setup.py), and run python, can it then see the package, and it works there.
Why isn't my export in bashrc making the package available from anywhere?
Is there something I have done wrong in the above?
To answer your question about the export path. Do you have $PYTHONPATH as a part of your $PATH? If not you should add it to path.
The best way to handle this scenario in my opinion is to use a virtual python environment. There are a couple to choose from, but I like virtualenv the best. The reason to take this approach is because you can manage different versions of python in separate folders. And have separate packages installed in these folders. I recommend looking into it as it is a very useful tool. If you want an examole of how to use it i can provide that https://virtualenv.pypa.io/en/stable/

Categories

Resources