Namespace package with both tarball and egg in Python - python

I've followed this tutorial to make a package with namespace. Then I use pip install xxx.tar.gz to install and everything works like expect.
The problem is that my environment has already a lots of packages with the same namespace and installed with easy_install and eggs, and python can not find the old packages anymore. I understand that if I create tar.gz instead of eggs for all the olds pacakges, it would work fine but this is a lots of time to spend.
How can I make the new and old packages work together with two different installation methods ?
Thanks

I just ran into the same problem (I think). It appears that this is a well known problem. The solution given to me was to just use pip for everything. I was specifically using python setup.py install alongside pip install w/e and it wasn't working, I'm guessing yours is roughly the same problem.

Related

Installed site-packages are not stored in Ubuntu?

I got this error even though I did install the PyQt5 package (yesterday, it worked normally)
and then I find the location of the site-package python, but nothing there? Not even a single one (I did install many packages yesterday)
I try to reinstall with homebrew and pip, and in both cases, it noticed that my package was installed (for homebrew, it said that I have to reinstall instead of using install since the package was already there)
When I check, there is only one folder of python so there was no misunderstanding about the python package in this case.
Can someone tell me why did it happen and how to solve it?
enter image description here

Module or Incorrect Python Version Problem?

I'm installing a bunch of python modules on my system that are specific to this code I am going to be working with. Specifically, I used pip install pyda to get the pyda module. To make sure I had gotten all the modules, I went through and ran some of the code snippets, and came across the following error:
ModuleNotFoundError: No module named 'pyda.utilities'
I tried using pip install pyda.utilities, but that honestly doesn't make sense, it should have just come with the pyda module. According to this website https://pypi.org/project/pyda/ it seems like it should come with the package. I tried determining if I just installed it in the wrong python version, but I'm having a difficult time forcing it to use the specific python version that I installed the module in (specifically, I tried to create an alias for /usr/bin/python3.7 or something like this as I have seen on other websites, but it just fusses at me that this is simply a directory, incredibly unhelpful because I can't find the corresponding executable, so I'm a bit confused here).
This is a very long question likely with a very simple answer, any thoughts or help on what the issue might be would be appreciated.
Edit: I have determined that it's a package problem, not a python problem. The command 'pip install pyda' is not actually installing everything, oddly enough, which is why it cannot find the pyda.utilities module. Unfortunately, I think this means I will have to install the package manually. I will keep this question posted because of the useful answer on virtual environments, so thanks everyone.
The answer is indeed straightforward. As #Chris indicated in the comments, start using virtual environments.
It's not as complicated as it sounds and there's plenty of tutorials on getting started with virtualenv for Python, like https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/
The basic steps:
check you're using the version of Python you want in your virtual environment
if you don't, change directories to where it lives
ensure you have pip and it works
check if you have virtualenv and if you don't pip install virtualenv
create a virtual environment virtualenv /your/env/folder/here
activate the virtual environment with /your/env/folder/here/Scripts/activate
After that, just install the packages you need with pip and they will end up in your virtual environment, with no interference from other Python versions or packages.
Check your python version, if it does not work restart your computer and try run setup.py install on the python command line

Do executables like pip.exe require python to work?

I am relatively new to Python so please pardon my ignorance. I want to know answer to following questions
How does pip know the location to install packages that it installs? After a built of trial and error
I suspect that it maybe hardcoded at time of installation.
Are executables like pip.exe what they call frozen binaries? In essence, does it mean that pip.exe will run without python. Again after a bit of trial and error i suspect that it requires a python installation to execute.
P.S: I know about sys.prefix,sys.executable and sys.exec_prefix. If there is anything else on which the questions i asked on depends, pls link me to same.
PIP is a package manager for Python packages, or modules if you like.
pip when used with virtualenv will generally install packages in the path /lib//site-packages.
For example, I created a test virtualenv named test, and the django folder is in test/lib/python3.7/site-packages/django.
At the time of installation, you must have set up environment variables, and that is how pip recognizes directories.
pip.exe which is placed under path\Scripts needs a python installation and can't run without one. It is hardwired against a specific python interpreter, and can't install packages for another one. If you have 7 different python versions installed on your system, you will also have 7 different versions of pip.
Since it is bound so tightly, pip was at some point even included with the python standard library (see pep-0453 for details).
This also answers the other part of your question of how pip figures out the right location - there is only one location it can install to, the side-packages of the python interpreter it is bundled against.

Editing a python package

The question is really simple:
I have a python package installed using pip3 and I'd like to tweak it a little to perform some computations. I've read (and it seems logical) that is very discouraged to not to edit the installed modules. Thus, how can I do this once I downloaded the whole project folder to my computer? Is there any way to, once edited this source code install it with another name? How can I avoid mixing things up?
Thanks!
You can install the package from its source code, instead of PyPi.
Download the source code - do a git clone <package-git-url> of the package
Instead of pip install <package>, install with pip install -e <package-directory-path>
Change code in the source code, and it will be picked up automatically.

How can I use pywin32 with a virtualenv without having to include the host environment's site-packages folder?

I'm working with PyInstaller under Python 2.6, which is only partially supported due to the mess MS have created with their manifest nonense which now affects Python since it is now MSVC8 compiled.
The problem is that the manifest embedding support relies on the pywin32 extensions in order to build which is a pain because without including the host's site-packages folder when I create the virtualenv (kinda defeats the point in a build environment) I cannot find a way to install the required extensions so they are accessible to PyInstaller.
Has anyone found a solution to this issue?
I found http://old.nabble.com/Windows:-virtualenv-and-pywin32--td27658201.html (now a dead link) which offered the following solution:
Browse http://sourceforge.net/projects/pywin32/files/ for the URL of the exe you want
Activate your virtualenv
Run easy_install http://PATH.TO/EXE/DOWNLOAD
This works with modern versions of setuptools (circa February 2014, reported by tovmeod in the comments).
If you are using an old version of setuptools (or distribute it merged back into setuptools), you may get this error message:
error: c:\users\blah\appdata\local\temp\easy_install-ibkzv7\pywin32-214.win32-py2.6.exe is not a valid distutils Windows .exe
In which case:
Download the exe yourself
Activate your virtualenv
Run easy_install DOWNLOADED_FILE.exe
I rather hopefully tried "pip install" rather than "easy_install", but this didn't work, and likely never will (citation needed).
Finally, I found but haven't tested a solution at http://www.mail-archive.com/python-list#python.org/msg272040.html which is:
Solved this by copying the pywin32.pth file into my virtualenv site-packages
and editing the file to point to the path.
If the other options don't work for you, maybe this will?
For Python 2.7 or 3.x use pypiwin32.
pip install pypiwin32
OK, well since I had to find a way forward I improvised. I've internally created a git repository with a hacked-together version of pywin32 that will install within a virtualenv using the standard setup.py script. It took a lot of fiddling to make it work right but I managed to get it to load and the dependent code now works as I need it to. If people feel this would be of benefit to the community please post a comment: if I get enough I'll try and put something up on my github account.
This may have been improved since previous answer, since I've successfully installed pywin32 on sandbox on several machines without any specific "hacks" :
$ virtualenv sandbox
$ sandbox\scripts\activate
(sandbox) $ git clone https://github.com/Travis-Sun/pywin32.git
(sandbox) $ cd pywin32
(sandbox) $ python setup.py install
Tested with following environment :
windows 7
git
python 2.7.10 with virtualenv
VS2008. It may also work (but I've not tested yet) with
http://www.microsoft.com/en-us/download/details.aspx?id=44266
Edit: Scratch this for now, appears to be some problems with the installation still...
I got rather tired of the whole situation, and just created a set of converted wheels ("wheel convert <.exe>"). I'll try and keep them maintained for the most recent build, but do shout if there are any issues.
https://tr00st.co.uk/python/wheel/pywin32/
Installation can be done easily using pip and pointing to the package matching your version and architecture. For example, for Python 3.5/amd64:
pip install https://tr00st.co.uk/python/wheel/pywin32/pywin32-219-cp35-none-win_amd64.whl
Caveat: The --upgrade process currently fails, as the uninstall procedure is unable to clean up after itself (Access Denied when cleaning up win32api.pyd) - this is only when removing the temporary directory, which can be manually deleted. Easiest way around this is to uninstall and reinstall instead of upgrading, then manually delete the temporary folder.

Categories

Resources