Installing and running Wheel file Pypi - python

I have a python tool that I run from the terminal and I would like to upload it as a bdist on Pypi to make a ready to use tool. (like an .exe on Windows)
While uploading it to Pypi (the test version of the service) I've used the command python -m build which creates both the .tar.gz and .whl file.
When doing pip install MyTool it installs the tool as a package, hence I cannot execute it from terminal (I mean just by calling the name of the package), I can execute it by running python3 path_to_....MyTool/MyTool.py but this is not what the end-user is supposed to do.
The goal is to have:
pip install MyTool (to install it)
MyTool or ./MyTool (to execute it)
I've tried to use the command python3 -m build --wheel in order to just create the .whl file and upload it to a new project without the .tar.gz file but still doing pip install MyTool it just installs the package (which i can import into my file) but I can't execute from terminal with ./MyTool.
I include to screen to help solve the question:
Screen of the .toml file
Screen of the setup.cfg file
How to make MyTool into a ready to use python application?
Thanks for your help!!

I found the solution:
the setup.cfg file was missing the options.entry_points:
[options.entry_points]
console_scripts = tool = MyTool:main
The syntax for entry points is specified as follows:
<name> = [<package>.[<subpackage>.]]<module>[:<object>.<object>]
url: https://setuptools.pypa.io/en/latest/userguide/entry_point.html

Related

What is the preferred way to develop a python package without using setup.py

I am developing a python package, and I don't want to have to keep running pip install . to reinstall my package every time I change something. Using the -e or --editable doesn't seem to work unless I have a setup.py file, nor does --no-use-pep517. I have a pyproject.toml instead, as is preferred nowadays if I am not mistaken. So, what is the preferred way to do this nowadays?
My package is just a CLI script, but it imports some functions from another file in the same directory called utils.py. When developing, I can't just run the script manually rfrom the terminal, because then I get name_of_package is not a package from the line
from name_of_package.utils import function, whereas If i just have
from utils import function, I can run the script from the terminal, but when I pip install it, it says there is no module named utils.
I did install poetry and installed my dependencies, ran poetry shell and then tried to run my script with poetry run /path/to/script.py, but I kept getting an error that my package wasn't a package.
If you want to keep using setuptools as "build back-end" then you can replace the setup.py script with a setup.cfg declarative configuration file and still be able to do "editable" installations (independently of whether or not you have a pyproject.toml file).
There is now PEP 660 which standardizes editable installations. The following tools have support for PEP 660:
PDM
Flit
Hatch
Poetry
On top of setuptools-based projects, all projects that use a PEP 660 build back-end should be installable as editable by pip (python -m pip install --editable .).

How to use another python project function into your project

I'm working with Django in a project, I want to use a python function from a project in Github, I can't install this project as a library with pip install dicom-exporter because it doesn' work.
The project I want to use:
https://github.com/KitwareMedical/dicom-exporter/
the function I want to use :
dicom-exporter <path/to/dicom/folder> <path/to/output.vti>
The project contain setup.py file where there is script entry-point,
Please How can use this project in my django project.
there is a simple way to do this in python
make sure that the file you want to import your function from is in the same directory as your project
make sure that the file you are importing the function from isn't named like an already existing python module
you can import the function into your project by writing into your project:
from [name of the file that contains the function] import [name of the function you want to import]
In this very case though you can simply type in your terminal pip install . as stated here
Its very simple as the Readme file in the project says you would use pip install that ends with a dot. But you will need to open the where you downloaded the project, in its directory contains the Setup.py in your command prompt in other to use the [pip install .], so make sure to download the project clone as a zip file and unzip in to the directory where you will find it in your command prompt and run the pip install .
#First navigate to where the project directory contains the setup.py file in your
# command prompt and run pip install that ends with a dot
pip install .

How do I run this python script?

I'm new to python, and I was wondering if you could help me run a python script. I'm trying to run a script called PunchBox from Github: https://github.com/psav/punchbox. So far, I have Python 3.9.5 and Git Bash.
In the GitHub page, it says:
To install, clone the repo, cd into it and then execute the following:
virtualenv -p python2 .pb2
source .pb2/bin/activate
pip install -U pip
pip install .
What does this mean exactly? Where do I run this code?
So far, I tried downloading the zip file from GitHub, installing Python 3.5.9, using cmd, finding the directory with cd, and running that code; but got an error:
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name punchbox was given, but was not able to be found.
error in punchbox setup command: Error parsing C:\Users\Mi\Downloads\punchbox-master\punchbox-master\setup.cfg: Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name punchbox was given, but was not able to be found.
There's also a requirements.txt that lists additional scripts needed:
pre-commit
click
mido
pbr
PyYAML
svgwrite
Do these install automatically upon running the script for the first time?
I'm a little confused why I'm getting an error. Do you know what I'm doing wrong?
Thank you so much!
Giovanni
I assume you are new to programming. You have to write these lines in a terminal.
On Windows, it is Command Prompt or PowerShell Applications (latter preferred). On macOS, it is terminal
Copy all these lines at once, and paste them to your preferred terminal. The terminal will automatically run these one after the another.
FYI: Venv is a python package to create a virtual environment. The preceding commands set up the environment. Now install the required dependencies using this command instead of the last command (pip install .)
pip install -r requirements.txt
Based on your comment, it looks like you don't have virtualenv installed in your system. You may install it using the command pip install virtualenv.
Now, as you are using a Windows machine, you may open a Command Prompt or Windows PowerShell window and navigate to the directory where your cloned project resides.
Now, execute the following commands.
virtualenv -p python2 .pb2
.pb2\Scripts\activate.bat
pip install -U pip
pip install -r requirements.txt
Once you are done working in your virtual environment (which is named .pb2), you may close it by executing deactivate command.
#Giovanni T.
See, as far as you have installed Python and also downloaded the GitHub Repository as a zip file.
pip install -r requirements.txt
Just run this command.
Please make sure that the directory is pointing to the folder where this requirements.txt file is stored.

How to install library with pip-console?

I downloaded some python library package (for example uncompile2) from GitHub. How I can install it into Qpython from the directory in my android device with pip-console? Or at least to try install...
You could install it directly through pip console, just type "pip install "
Or, you can make a .sh file with contents
python /your/path/to/the/package/setup.py install
Or at least I think so.
You could copy the modules you want installed into the site-packages folder
using a file manager open up the folder:
/sdcard/com.hipipal.qpyplus/lib/python2.7/site-packages/
that is where you can put the modules, i have not tried it with the pip console.

Setup tools install command differences

What are the differences between the below commands
python setup.py install develop
Doesn't work for me error No such file or directory: 'build/bdist.macosx-10.7-intel/egg/test-easy-install-37886.pth'
python setup.py develop
Works for me appears to make an .egg link file
python setup.py install
Works for me appears to make a .egg file which in .zip file format
Develop is a setuptools / distribute feature that allows you to add a project
to your Python environment without installing it - so you can continue
its "development"
In other words, when you call "python setup.py develop", setuptools will
compile the metadata and hook your project into Python's site-package,
but the packages and modules that will be used are the one in the
directory where you've run that command.
This is useful to continue working on your code and testing it without
having to run "python setup.py install" on every run
With develop, Python 'pseudo-installs' a package by running the setup.py script instead of install. The difference is a modification of the environment (it doesn't with develop), so a package can be imported from it's current location instead of a site-package directory. The advantage of this is you can develop packages that are being used by other packages, and you can modify source code in place with develop.
As far as "setup.py install develop", I've never seen anyone use that before, sorry.
source
source
source
python setup.py install develop
Is a wrong command.
When you use develop you use the current code when you run your application.
When you useĀ install and then modify you code, your modifications will not be taken in account while running your app. until you rerun install or develop.

Categories

Resources