Distribute pip package no source code - python

I have an "homemade" python package which i can successfully install via pip package manager.
I'd like ti distribute it without giving the source code (*.py files)... i tried to compile them with
python -m compileall .
and then installed by typing pip install .
However it can't find the module when i try to import it in my application.
ImportError: No module named...
What do you suggest to solve?
Thanks

I guess it is to do with setuptools not packaging up *.pyc files, because normally you don't want them.
You should create a file MANIFEST.in with the content
global-include *.py[co]
global-exclude *.py
This tells setuptools to exclude *.py source files and include *.pyc compiled files.
Afterwards create a source distribution package
python setup.py sdist
or a wheel
python setup.py bdist_wheel
which also compiles C extensions.

Related

pip not installing Cython source files

I have one *.pyx (Cython) source file in my package but it was not getting included in the source distribution when I ran:
$ python3 setup.py sdist
Therefore, I added a MANIFEST.in file to include all *.pyx files. My package requirements specify Cython as a requirement: therefore all my users would have Cython installed. In other packages, I use pyximport:
import pyximport; pyximport.install(language_level=3)
from mycythonpackage.mycythonmodule import *
Now when I run sdist I correctly see the *.pyx files packaged in the tarball. However, when I extract the tarball to a folder, and then execute:
$ sudo pip3 install .
The installation proceeds perfectly. But the pyx files were not installed and therefore, my package is unable to find the Cython module when I run it.
Just including/installing the pyx files in my package will solve my problem as I expect my users to run my package as is, and Cython will compile them on the fly. I do not want to compile/build the pyx files nor do I want/need to package the .so / .c / ... files. I just want the plain *.pyx files installed. How can I instruct pip to forcefully include/install the *.pyx files during installation?
I found the solution: modify the setup.py file to include:
package_data = { 'mypackage': ['mycythonmodule-filename.pyx']},
include_package_data = True

python3 setup.py install is failing (RHEL 8)

Issue:
#python3 setup.py install
is failing
Environment: RHEL 8 UBI container
I have a setup.py that looks like this: (any pointers or updates on this setup.py would be appreciated)
import setuptools
print('python/setup.py')
setuptools.setup(
name="process_data",
version="1.0",
description="desc",
author="FirstName LastName",
author_email="dude#abides.abide",
url="https://some.com",
packages=setuptools.find_packages(),
)
I have a directory structure like so (<some>.py in every directory, along with __init__.py):
python/
setup.py
<dir>/__init__.py
<dir>/__init__.py
<dir4>/__init__.py
<dir4>/<sub-dir1>/__init__.py
<dir4>/<sub-dir1>/<sub-dir>__init__.py
I want code in each of these directories to be part of a module package so I can import, nested however deep.
I'm doing this:
#cd python
#python3 setup.py install
I get this error:
python/setup.py
running install
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the
installation directory:
/usr/local/lib/python3.6/site-packages/test-easy-install-1625.write-test
[Errno 2] No such file or directory: '/usr/local/lib/python3.6/site-packages/test-easy-install-1625.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/local/lib/python3.6/site-packages/
This directory does not currently exist. Please create it and try again, or
choose a different installation directory (using the -d or --install-dir
option).
Questions:
Where is this coming from: test-easy-install-1625.write-test ? (so confused as to what this is)
On my system, indeed this directory does not exist (why is python3 setup.py install looking there? what told it to look there?):
/usr/local/lib/python3.6
There is nothing in my setup.py to indicate to look there.
I looked all over, and it looks like my /site-packages/ directory is here (where other modules are installed, when I ran pip)
`/usr/local/lib64/python3.6/site-packages/`
How do I fix this?
Thank you, I so badly need to get this working right away. I have been working on Windows, and >python setup.py install simply works there.
Are there any env variables I should have setup?
I simply installed python with: dnf -y install python36 that's it. (the latest version available in any RHEL 8 package repo for installation).
I ran into this same error and I was able to fix it by creating a symbolic link. I accept someone else maybe able to offer a more elegant solution and I welcome it.
sudo mkdir /usr/local/lib/python3.6
sudo ln -s /usr/lib/python3.6/site-packages /usr/local/lib/python3.6/
I assume you had enter python command mode, if you don't, the following commands are needed, notice to set variable Path and PythonPath of yours:
setlocal
set env_name=python3.6
set Path=C:\Users\s41167\Miniconda3\envs\%env_name%;C:\Users\s41167\Miniconda3\envs\%env_name%\Scripts;%Path%
set PythonPath=C:\Users\s41167\Miniconda3\envs\%env_name%\Lib\site-packages
cd C:\Users\s41167\Documents\%env_name%
cmd.exe /K activate %env_name%
if you enter python command mode, you can use pip to insall the package:
pip install <package location> --target <install location> --upgrade
below is my install command and result:
(python3.6) C:\Users\s41167\Documents\python3.6>pip install ./python_package --t
arget ./target --upgrade
Processing c:\users\s41167\documents\python3.6\python_package
Building wheels for collected packages: process-data
Building wheel for process-data (setup.py) ... done
Created wheel for process-data: filename=process_data-1.0-cp36-none-any.whl si
ze=1721 sha256=ef5eaf061000f30d472e5dde268694733e40a3f8a4a29fa78faec69f125443c9
Stored in directory: C:\Users\s41167\AppData\Local\Temp\pip-ephem-wheel-cache-
v6lt_ndp\wheels\61\01\f5\07e0760baa10d63e1c43b37eadbb55b79828f4fe337209026a
Successfully built process-data
Installing collected packages: process-data
Successfully installed process-data-1.0
(python3.6) C:\Users\s41167\Documents\python3.6>
and the file arrangement:
.\python_package
__init__.py
setup.py
\directory
__init__.py
\directory4
__init__.py
\sub_dirctory1
__init__.py
in Linux use
sudo python3 setup.py install
in windows use
python setup.py install
or
python3 setup.py install

Installing Python package from version control where setup.py is not in the project root

I'm trying to include the pyobjc package in my pip requirements file, but I need a committed version that doesn't have a release yet in order to pull in a much needed bug fix. The pyobjc package is a pseudo-package to install all the other framework dependencies.
I can specify the HG path in the pip requirements just fine. The problem I'm facing is that the repository doesn't have a setup.py in the root directory. Instead it has a subdirectory labeled pyobjc (with all the framework subdirectories alongside) that contains setup.py. In the root directory of the repo, there's a file labeled install.py that pyobjc's readme recommends using when installing from source.
Does anyone have any idea how to call install.py from pip instead of setup.py or point to the subdirectory location?
In the pyobjc/pyobjc subdirectory I see setup.py, not `install.py.
pip can be advised to look into a subdirectory of a VCS repository for setup.py:
pip install -e 'hg+https://bitbucket.org/ronaldoussoren/pyobjc#39c254b20bf2d63ef2891cb57bba027dfe7e06e8#egg=pyobjc&subdirectory=pyobjc'

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.

Can not install hcluster from pypi under python 2.6 on xp

I am using the setup.py file supplied with hcluster with the following lines added:
sys.path.append("c:\\Program Files\\Python26\\Lib\\site-packages\\hcluster-0.2.0")
sys.path.append("c:\\Program Files\\Python26\\Lib\\site-packages\\hcluster-0.2.0\\hcluster")
Then used setup.py as follows:
"c:\program files\python26\python.exe" "c:\Program Files\Python26\Lib\site-packages\hcluster-0.2.0\setup.py" install
I get the following error messages:
running install
running build
running build_py
error: package directory 'hcluster' does not exist
Don't know if it trying to read or write hcluster.
Any help appreciated
You don't need to add packages in site-packages in sys.path.
Did you copy the hcluster in site-package manually? It is not the correct way to do it.
2.1 You should have the hcluster outside the site-packages say in your home directory and then run "python setup.py install"
2.2 This will put the package after build into site-package directory. This is where all external package reside by default after they are installed.
Remove the folders related to hcluster from site-packages and install with instruction 2.
Read the following to understand your error: http://docs.python.org/install/index.html

Categories

Resources