I have a problem, i develop an application with python and i use some libraries like flask, sqlalchemy, etc...
The problem is that i have a define version of each library, and I want to deploy this python application in another computer without internet,
can I create a package or use setup.py and include the other package with path ?
I've already try this code, but the library aren't imported they said that :
ModuleNotFoundError: No module named 'cx_Oracle'
My code is:
from distutils.core import setup
setup(
# Application name:
name="MyApplication",
# Version number (initial):
version="0.1.0",
# Packages
packages=["App","App/service"],
include_package_data=True,
install_requires=[
"flask","cx_Oracle","pandas","sqlalchemy"
],
)
install_requires is a setuptools setup.py keyword that should be used to specify what a project minimally needs to run correctly.
It won’t install those libraries.
Maybe you should try pyinstaller (https://www.pyinstaller.org) to make ready runnable file to run on the other computer.
Related
I am trying to build a standalone app that utilises Pandas. This is my setup.py file:
from setuptools import setup
APP = ['MyApp.py']
DATA_FILES = ['full path to/chromedriver']
PKGS = ['pandas','matplotlib','selenium','xlrd']
OPTIONS = {'packages': PKGS, 'iconfile': 'MyApp_icon.icns'}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app','pandas','matplotlib','selenium','xlrd'],
)
The making of the *.app file goes smoothly, but when I try to run it, it gives me the following error:
...
import pandas._libs.testing as _testing
File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing
ModuleNotFoundError: No module named 'cmath'
I tried to include ‘cmath’ in my list of PKGS and in setup_requires in the setup.py file, but when I tried to build the app using py2app it gave me the error:
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('cmath')
I am stuck. I couldn't find anything useful online. cmath should be automatically included from what I have been reading. Any ideas on where is the problem and how can I fix it?
I think I have found a solution: downgrade to Python version 3.6.6.
See: python 3.6 module 'cmath' is not found
To uninstall Python I followed this process: https://www.macupdate.com/app/mac/5880/python/uninstall
Then I installed Python 3.6.6: https://www.python.org/downloads/release/python-366/
With Python 3.6.6, Py2App seem to work no problem and includes Pandas smoothly.
It seems that for some reasons cmath is not included in the latest versions of Python? I might be wrong. Please let me know what you think and if you have any questions.
P.S.: I am using MacOS (Mojave 10.14.6) and PyCharm.
I had a similar issue with py2app and cmath. I solved this by adding import cmath into the main script. (MyApp.py in your case) I think doing so may have the modulegraph to add the cmath library files.
I'm using a 64bit Windows machine with 64bit python3. I need to build a installable package for a windows 32bit machine and stumbled upon the cross compile feature of the bdist feature: https://docs.python.org/3/distutils/builtdist.html
I'm using a setup.py like this:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages
setup(name='mypackage',
version='1.0',
description='Some Description',
install_requires=['requests'],
package_dir={'': 'src'},
packages=[''],
entry_points = {'console_scripts': ['somescript = foobar:main']},
)
And build the install packages like so:
python setup.py build --plat-name=win32 bdist_wininst --user-access-control auto
python setup.py build --plat-name=win-amd64 bdist_wininst --user-access-control auto
In both cases I get the correct executeable format for the specified architecture but the defined console_script somescript was not executeable after installation.
The python documentation says that I need to crosscompile the whole python package for windows - but I'am uncertain if this is even necessary because the installer was for the right architecture and I got no error message while the build process.
Is there something wrong with the command? Do I really need to crosscompile or is it sufficiant to have a second 32bit installation of python?
As I found out this is a reported bug https://github.com/pypa/setuptools/issues/253
The setuptools do only check for the OS architecture and ignore the plat-name string for the installation of scripts.
Workaround (until this issue is closed): Use the target architecture for building the wininst.
I am building a package in Cython. I am using the following as the structure for setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
import scipy
extensions = [
Extension("xxxxx",["xxxx/xxxxx.pyx"],
include_dirs=[numpy.get_include(),"."]),
Extension("nnls",["xxxxx/xxxxx.pyx"],
include_dirs=[numpy.get_include(),"."]),
]
setup(
name='xxxxxx',
version='0.0.0',
description='''********''',
url='xxxxxxx',
author='xxxxx',
author_email='xxxxx',
packages=[
'xxxxx',
],
install_requires=[
'cython',
'numpy',
'scipy',
],
ext_modules=cythonize(extensions),
)
However, I am getting an error upon installation in Python 3. It is working in Python 2 however, it is not compiling in Python 3 having the following error:
dynamic module does not define module export function
How can I solve this problem? Is the structure of the setup.py the reason why this is not compiling?
You need to call setup.py with Python 3 (python3 setup.py build_ext, maybe --inplace). It's because Python 3 defines a different name for the init function called when the module starts, and so you need to build it using Python 3 to ensure the correct name is generated.
See dynamic module does not define init function (PyInit_fuzzy) and How to specify Python 3 source in Cython's setup.py? for slightly more detail (it's bordering on a duplicate of these questions, but isn't quite in my view)
I experienced this and found that I had to use the same name of .pyx as the module name, e.g.
makefile:
# (default)
# INSTALL_DIR:=/usr/lib/python3.6/site-packages
# (my venv)
INSTALL_DIR:=/home/<username>/python3_venv/lib/python3.6/site-packages
all:
sudo python3 setup_myproj.py install --install-lib ${INSTALL_DIR}
setup_myproj.py
from distutils.core import setup, Extension
from Cython.Build import cythonize
ext = Extension("myproj",
sources=["myproj.pyx", "myCppProjFacade.cpp"],
<etc>
language="c++"
)
setup(name="myproj",
version="0.0.1",
ext_modules=cythonize(ext))
client module, run after installing to venv
import myproj as myCppProjWrapper
...
I also found that if the "myproj" names are different, under <python-lib-dir>/<python-vers>/site-packages the .so and .egg-info names are different and the client fails to load it.
In addition I found that the client's environment does not need to have the cython package installed.
I had the same error for torchvision. FIxed it by downgrading the installation versions:
pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html
I am attempting to use py2app to bundle a small Python app that I've made in Python 2.7 on Mac. My app uses the Watchdog library, which is imported at the top of my main file:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
When running my program, these import statements work just fine, and the program works as expected. However, after running py2app, launching the bundled application generates the following error:
ImportError: No module named watchdog.observers
At first I thought it was something to do with the observers module being nested inside watchdog, but to test that, I added the line
import watchdog
to the top of my program, and then upon running the app, got the error
ImportError: No module named watchdog
so it seems that it actually can't find the watchdog package, for some reason.
I tried manually adding the watchdog package using py2app's --packages option:
$ python setup.py py2app --packages watchdog
but it had no effect.
My unbundled Python program runs just fine from the command line; other downloaded modules I've imported are giving no errors; and I have successfully bundled a simple "Hello World!" app using py2app, so I believe my setup is correct.
But I'm kind of out of ideas for how to get py2app to find the watchdog package. Any ideas or help would be greatly appreciated.
Edit: Here is the text of my setup.py, as generated by py2applet. I haven't modified it.
from setuptools import setup
APP = ['watcher.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Try manually including the desired packages in the setup.py file:
from setuptools import setup
APP = ['watcher.py']
DATA_FILES = []
PKGS = ['watchdog', /*whatever other packages you want to include*/]
OPTIONS = {
'argv_emulation': True,
'packages' : PKGS,
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
I had installed watchdog 0.5.4, a very old version as it turns out, and got the same error. The error was fixed after upgrading it to 0.8.3:
pip install watchdog --upgrade
Your problem generally indicates that the package (in your case "watchdog", or one of its dependencies) isn't installed, or at least not in a location that py2app expects to find packages.
Do you use the same python command for running py2app as for running the script from the command-line? What is the message of the ImportError you're getting (both when importing "watchdog" and importing "watchdog.observers"?
The (way too long) output of py2app should also mention that it cannot find some packages, and which ones.
As alluded to in one of the answers py2app does not seem to search the same set of paths that are used by the python interpreter, so you need to copy the python library to one of those locations.
For example I've got the MacPorts version of Python installed and found that when I had a module installed in /Library/Python/2.7/site-packages/ py2app wasn't finding it, but it would find it when I copied it into /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. So to copy it over run :
sudo cp /Library/Python/2.7/site-packages/thatmodule.so /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
Then run the py2applet script again and build the app to check. If it's elsewhere you can do a search for all site-packages locations using Spotlight's command line interface:
mdfind -name site-packages
how can I make setup.py file for my own script? I have to make my script global.
(add it to /usr/bin) so I could run it from console just type: scriptName arguments.
OS: Linux.
EDIT:
Now my script is installable, but how can i make it global? So that i could run it from console just name typing.
EDIT: This answer deals only with installing executable scripts into /usr/bin. I assume you have basic knowledge on how setup.py files work.
Create your script and place it in your project like this:
yourprojectdir/
setup.py
scripts/
myscript.sh
In your setup.py file do this:
from setuptools import setup
# you may need setuptools instead of distutils
setup(
# basic stuff here
scripts = [
'scripts/myscript.sh'
]
)
Then type
python setup.py install
Basically that's it. There's a chance that your script will land not exactly in /usr/bin, but in some other directory. If this is the case, type
python setup.py install --help
and search for --install-scripts parameter and friends.
I know that this question is quite old, but just in case, I post how I solved the problem for myself, that was wanting to setup a package for PyPI, that, when installing it with pip, would install it as a system package, not just for Python.
setup(
# rest of setup
console_scripts={
'console_scripts': [
'<app> = <package>.<app>:main'
]
},
)
Details