Unable to load python entry_point when developing python package - python

I am trying to develop a python package that is importable and also has entry_point to call from shell.
When trying to call the entry point I get:
pkg_resources.VersionConflict: (pysec-aws 0.1.dev1 (/Users/myuser/PycharmProjects/pysec-aws), Requirement.parse('pysec-aws==0.1.dev0'))
Essentially what I did before getting this error, is incrementing the version from 0.1.dev0 to 0.1.dev1 in setup.py, and running python setup.py sdist and then pip install -e .
What am I doing wrong? What is the proper way to install development versions of packages you are actively developing and bundling with setuptools?

The error is complaining that the application version does not match the version declared in setup.py. Try checking the __version__ set in your application.
You might consider using a single source for the version to avoid this problem. There are a number of different options outlined at https://packaging.python.org/guides/single-sourcing-package-version/. One simple technique, if there are not any external dependencies, is
import myapp
setup(
...
version=myapp.__version__
...
)

The only thing that fixed this issue was to create a new virtualenv.
Apparently my virtualenv/bin had compiled (.pyc) and non-compiled (.py) references to the old version for some reason - they were probably not upgraded / removed when I installed the new version.
Once I created a new virtualenv and re-installed required packages I was able to resolve this issue.

Related

Pycharm install two branch version of the same module

I am using the cloudscraper python library, installed from the Pycharm UI.
Therefore, I am using the main version of this package.
I would like to try to use the dev version of this package, that can be downloaded through github from the relative branch (https://github.com/VeNoMouS/cloudscraper/tree/dev). In order to install this dev package, I have to run python setup.py install.
Is there a way to keep both versions of this module? How can I install the dev package directly from the UI?
Python does not handle having multiple versions of the same library installed. See for example this related question.
Indeed, the solution is to modify the files for one of the version to give it a different name (for example cloudscraper-dev).
Or you could have two different virtual env, one for each version, but it requires to switch from one to the other.

Installing specific versions of python dependencies for a package inside that package

I have an installable python package (mypackage) and it needs to use specific versions of a number of dependencies. At the minute I have some .sh scripts that just pip these into an internal package folder (eg C:\Python27\Lib\site-packages\mypackage\site-packages). When mypackage executes it adds this internal folder to the beginning of the python path so that it will override any other versions of the required dependencies elsewhere in the python path.
I know this will only work if the user doesn't import the dependencies prior to importing mypackage but I will document this.
I want to remove the .sh scripts and integrate the above into either dist_utils install or pip standard installation process. What is the best way to do this? I know about install_requires but it does not seem to allow specification of a location.
I eventually found the virtualenv tool which solved the above problem much more elegantly than the solution I'd put in place:
https://docs.python.org/3/tutorial/venv.html

Windows Python Virtualenv Install PIL and MySQL

In windows I'm having trouble installing things such as PIL and MySQL inside my virtualenv for Python 2.7 64-bit.
I've downloaded extensions from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/ and installed them globally.
But how can I get them to apply to my virtualenv installation?
If I do a re-installation of virtualenv for my project, will it inherit the currently installed PIL and MySQL?
My main error is when I do a pip installed: error: Unable to find vcvarsall.bat
Now what I've read is I need Visual Studio to compile such things, and I'm hoping this isn't the only way to get things working.
Create your environment with the --system-site-packages option. Once you are in the virtual environment, if you try to import a package that isn't installed, it will try to find it in the global site packages and only if it can't find it there will it raise an ImportError.
This is by far the simplest way to do what you are trying on Windows - short of creating your own build environment - which I can tell you from my experience isn't always guaranteed to work.
If you do go with this approach, make sure you still add the package (and ideally pin it) in your requirements.txt file. This way if you were to deploy it on another environment, you will not miss any dependencies.

importError: no module named _winreg python3

Where can I download _winreg for python3 if I can at all. I have my 'windir' on E:\Windows. I do not know if cx_Freeze did not notice that. I am using cx_Freeze to create an msi installer.
As it says in the _winreg documentation, it has been renamed to winreg in Python 3.0. You should run the 2to3 tool if you're converting code that was written for Python 2.x.
I know this is an old question, but this was the first search result when Googling for ModuleNotFoundError: No module named '_winreg', and perhaps may be helpful for someone.
I got the same error when trying to use a virtual environment folder, which has been created using different (already deleted) python binaries. The solution was recreate the virtual environment:
Delete the virtual environment folder
Run python -m venv <name_of_virtual_environment>
I have found an easy solution for this, Even though i found it after a lot of Rnd, the solution implementation is so simple and straight forward. Hope it can help many people with the same problem.
If you dont have the latest version of Python installed on your machine, You need to download it from (https://www.python.org/downloads/) and then click on Add to path option and just finish the installer.
Please open CMD and move to the python latest version directory, then run the pip install package name (e.g) pip install pygame and it will be successful
1. C:\WINDOWS\system32>cd C:\Users\admin\AppData\Local\Programs\Python\Python37-32
2. C:\Users\admin\AppData\Local\Programs\Python\Python37-32>pip install Pygame
It will install the packages now without any issues.
Downloading
Successfully installed Pygame-1.9.4
C:\Users\admin\AppData\Local\Programs\Python\Python37-32>
If you are still facing issues in Pycharm after trying the above solution, please try the following steps too.
Create new virtual Environment from settings menu and select the latest version of python framework as Project Interpreter and give a new folder path.
select the pip package you want to import. Recompile the code and the error will clear.
Hope this helps.
When you encounter an error like module of simpleai not found,
use
pip install simpleai
in the prompt and then execute. It will get installed.

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