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
Related
I have an isolated Wintel host not able to pip or etc, which equals to have network opened to 'internet'.
I downloaded python embedded form python.org (on other machine), copied and unzipped it to O:\xip\Python on isolated machine.
Now it looks like:
libcrypto-1_1.dll
libffi-7.dll
libssl-1_1.dll
LICENSE.txt
pyexpat.pyd
python.cat
python.exe
python3.dll
python38.dll
python38.zip
python38._pth
pythonw.exe
select.pyd
sqlite3.dll
unicodedata.pyd
vcruntime140.dll
winsound.pyd
_asyncio.pyd
_bz2.pyd
_ctypes.pyd
_decimal.pyd
_elementtree.pyd
_hashlib.pyd
_lzma.pyd
_msi.pyd
_multiprocessing.pyd
_overlapped.pyd
_queue.pyd
_socket.pyd
_sqlite3.pyd
_ssl.pyd
i have PyPI requests package, did python setup.py install it on other machine and i copied \build\lib\ directory (which appears) into isolated machine O:\xip\Python\build\lib\requests\
my PATH have O:\xip\Python;O:\xip\Python\build\lib
my PYTHONPATH have O:\xip\Python\python38.zip;O:\xip\Python\build\lib;O:\xip\Python\build\lib\requests
When i go to python console and run import requests i get no module named 'requests'
1. Should I unzip this python38.zip?
2. should i have something more in PATH or PYTHONPATH?
3. Should i copy something more from machine where i did install of request package?
Any ideas what is wrong here?
The embedded distribution does not use environment vars. See here: Python Issue 28245
You should edit the python._pth file and put your additional paths there.
Alternatively, you could also extend sys.path before attempting the import.
I've tried setting meld as my mergetool to use with git doing:
git config --global merge.tool meld
git config --global mergetool.meld.path c:/Progra~2/meld/bin/meld
As outlined in answers to questions like:
How to set Meld as git mergetool
I used to have this working on my old work machine but now on my new machine where I have Python3 installed instead of 2.7 I am getting the following error whenever I try git mergetool:
C:/Program Files/Git/mingw64/libexec/git-core/mergetools/meld:
c:/Progra~2/Meld/bin/meld: C:/msys64/MINGW32/bin/python3.exe: bad
interpreter: No such file or directory
Any ideas what extra steps I need to make to get this to work with Python3?
EDIT: I have tried pointing directly to Meld.exe too but that causes the following crash:
The .../bin/meld script is mostly there for reference. You should set
git config mergetool.meld.path "C:/Program Files (x86)/Meld/Meld.exe"
You don't need to use Progra~2 notation unless you really want to for some reason.
The only issue that I am having is that it is not properly picking up the installed dependency extensions in C:/Program Files (x86)/Meld/lib. You need to add C:/Program Files (x86)/Meld/lib to your PATH environment variable, either with SET PATH=C:/Program Files (x86)/Meld/lib;%PATH%, or through the "Edit Environment Variables for your account" somewhere in control panel/start menu.
Alternative Approach
If you open C:\Program Files (x86)\Meld\bin\meld in a text editor, you will see that it is a shell script that is intended to be run in python3 (called from C:\Program Files\Git\bin\sh.exe most likely).
The first line of meld reads:
#!C:/msys64/MINGW32/bin/python3.exe
This issue does not pop up when using Meld.exe because it does not use the script through a python interpreter.
It is unlikely that the python interpreter is installed at that location on your machine. Instead, you can replace the shebang line to point to an existing interpreter. For example, on my machine, meld starts with:
#!C:/Users/MadPhysicist/AppData/Local/Continuum/anaconda3/python.exe
This still won't be enough for the script to find the meld package and all the installed GTK, cairo, etc. DLLs, so you have to tweak both the python and system paths. Insert the following before the line import meld # noqua: E402 (line ~78):
os.environ['PATH'] = os.pathsep.join((melddir, os.path.join(melddir, 'lib'), os.environ['PATH']))
sys.path[0:0] = [os.path.join(melddir, 'lib/python3.7/site-packages')]
I was not ever able to get the first line to set up Cairo, GTK, etc. correctly for meld. You can, however, skip the first line and just install the packages using conda or pip. You will still need to insert the meld package into sys.path.
Keep in mind that meld is compiled in 32 bits, as evidenced by the x86 in the install folder. You can only run it with a 32-bit python interpreter if you use the included DLLs, which may require additional installation. You do not need a 32-bit interpreter if your environment contains all the necessary packages already.
I know there is like a package directory on pypi, im curious to know where is the file that configures pip to look for the packages on pypi specifically. Im trying to understand the very basics of it, any related information would help.
https://pip.pypa.io/en/stable/user_guide/#configuration
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
I had the same question about the default package index. We can certainly override it in the pip.ini file or on the command line with the --index-url option, but that doesn't explain where the pypi.org default is configured.
So I went to the source-code, and it turns out that it is hard-coded in there.
I see it in at least two active source files:
index.py
locators.py.
This commit where the default was changed in 2018. It shows many other test and documentation files that have it hard-coded.
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.
on Windows 7, is there a mean to install Python 2.7.8 (64-bit) without replacing existing Python27 (64-bit) installation?
I am agree with Burhan Khalid but pay attention to PATH.
Indeed, if you execute .py with double click windows take the Python executable defined in PATH variable.
If you use Command Line Interface to execute Python file you will not have any problems.
It is due to python27.dll file. When we install Python2.7.x it use the dll file located in C:\Windows\System32\ (C:\Windows\SysWOW64 in 64 bits plateforme)
Please, follow these steps:
You must to install Python 2.7.0 in C:\Python270, copy Python27.dll in C:\Python270\path folder (you must create path folder).
You must to install Python 2.7.8 in C:\Python278, copy new Python27.dll in C:\Python278\path folder (you must create path folder).
In each Python folder (Python270 and Python278) you can create an run.bat file and append this content :
set PATH=%PATH%;Path
python.exe
And you try execute batch file and check python version.
Can you confirm me if it's works ?
The only way to accomplish this is to install it in a different location than the default C:\Python27.
You can set the install path in the Windows installer.