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 .
Related
I would like to use the following sdk in my python project -> https://github.com/LBank-exchange/lbank-api-sdk-v2. It has sdk's for 3 languages (I just want the python one). I tried to install it using the command:
pip install git+https://github.com/LBank-exchange/lbank-api-sdk-v2.git#egg=lbank
which gave the error
does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found.
Looks like the developer didn't bother to package it properly. It it was me using it, I would fork it on GH, add the setup.py and use the fork. Maybe a good exercise for you?
Meanwhile, to just get it to work, in your project "root":
git clone https://github.com/LBank-exchange/lbank-api-sdk-v2.git
ln -s lbank-api-sdk-v2/python-sdk-api/LBank ./LBank
Then in your code just import LBank. This will leave the cloned repo untouched (so you can git pull to update it later) and just link the module directory to the root. Alternatively you can just include the api directory in sys.path for imports to work.
Think there is nothing to install, if you want to be able to "import" and use it like other packages you install through pip install you can just add the folder to your sys-path:
import sys
sys.path.append("path")
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
I am new to python3 and I want to create a package that I can import from other python script.
So I created my package and I run
python3 setup.py sdist
to create my tarball.
when I move it to another directory to untar it and then install the package with
python3 setup.py install -user --prefix=
it's fine there is no error and it install in my site-package of python and when I run python3 I can import my lib and call its function.
But when I want to import this package in a script it tell me
ImportError: No module named test_package.pck1.addition
I know that I can add
import sys
sys.path.append('./test_package.0.1')
to fix it but I want to avoid that because it would mean always having to modify the path to the package when trying to use it in another script.
So How can I import my package without modifying the sys.path. Or how can I an install my package so that my script won't need that.
I tried a lot of installation process (using pip3, trying different option etc) nothing work as I expect it.
you created the python package 'toto.py'. you want to import it in the python script 'tata.py'. you write 'import toto' in the tata script and you place the file 'toto.py' in a directory contained in the PYTHONPATH environment variable.
Although I don't use python 2, it seems to me it is the same for python 2 and 3. Thus I'm not sure I understood the question.
I have a pytest test, let's call it test.py. I used to run this test outside of virtualenv; now I'm trying to run it inside a virtualenv sandbox.
The project is structured like this:
~/project/test # where test.py and all virtualenv files live
~/project/mylibrary
test.py imports from mylibrary. In the past, this worked because I have the code in ~/project/mylibrary installed into /usr/lib/python2.7/dist-packages/mylibrary.
I can't run virtualenv with the --system-site-packages flag. I also can't move the code from ~/project/mylibrary into the ~/project/test folder. How can I get access to the code in mylibrary inside my virtualenv?
You don't need to do anything special - as long as you are working inside a virtualenv, python setup.py install will automatically install packages into
$VIRTUAL_ENV/lib/python2.7/site-packages
rather than your system-wide
/usr/lib/python2.7/dist-packages
directory.
In general it's better to use pip install mylibrary/, since this way you can neatly uninstall the package using pip uninstall mylibrary.
If you're installing a working copy of some code that you're developing, it might be a good idea to install it in "editable" mode using pip install -e mylibrary/, which creates a link to your source directory so that your installed module gets updated as you edit the code.
The easiest way would be to add the directory containing the library to your sys.path
is there any method to create standalone .pyc program that will contain all modules inside, I just don't want to install all modules on every computer where I want to run this program. If this is not possible what else can I do?
You could install python packages locally inside your project, using command:
pip install -t <destination_folder> <package_name>
For example:
pip install -t . mock
Will install mock library into current directory. Then, when you do import mock in the files from that folder, you will be given local file.
You could also install all packages into subfolder of your project called lib or similarly, and than before you import that package call:
import sys; sys.path.insert(0, path_to_lib_folder)
You need to create virtual python environment.
There are two ways:
VirtualENV. It creates virtual environment. So you can install python modules in it and just copy to another server.
(RECOMMENDED) Buildout. It also creates virtual environment. However you don't need to install all things and update every time you need. You just need to write simple buildout config and buildout install everything for you and keeps it up to date. Also buildout can install software which may be non-Python-based, for example some kind of database and so on. And everything will be installed locally in virtual environment.