Using PyCharm and setup.py with packages with period in them - python

I am using PyCharm to generate a setup.py file for my project. The following file is generated:
from setuptools import setup
setup(
name='untitled',
version='',
packages=['venv.lib.python3.6.site-packages.PyQt5', 'venv.lib.python3.6.site-packages.PyQt5.uic',
'venv.lib.python3.6.site-packages.PyQt5.uic.Loader', 'venv.lib.python3.6.site-packages.PyQt5.uic.port_v2',
'venv.lib.python3.6.site-packages.PyQt5.uic.port_v3',
'venv.lib.python3.6.site-packages.PyQt5.uic.Compiler', 'venv.lib.python3.6.site-packages.py2app',
'venv.lib.python3.6.site-packages.py2app.recipes', 'venv.lib.python3.6.site-packages.py2app.recipes.PIL',
'venv.lib.python3.6.site-packages.py2app.bootstrap', 'venv.lib.python3.6.site-packages.py2app.converters',
'venv.lib.python3.6.site-packages.py2app.apptemplate',
'venv.lib.python3.6.site-packages.py2app.bundletemplate', 'venv.lib.python3.6.site-packages.altgraph',
'venv.lib.python3.6.site-packages.macholib', 'venv.lib.python3.6.site-packages.modulegraph',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.req',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.vcs',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.utils',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.compat',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.models',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.distlib',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.distlib._backport',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.colorama',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.html5lib',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.html5lib._trie',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.html5lib.filters',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.html5lib.treewalkers',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.html5lib.treeadapters',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.html5lib.treebuilders',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.lockfile',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.progress',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages.chardet',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages.urllib3',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages.urllib3.util',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages.urllib3.contrib',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages.urllib3.packages',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.requests.packages.urllib3.packages.ssl_match_hostname',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.packaging',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.cachecontrol',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.cachecontrol.caches',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.webencodings',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip._vendor.pkg_resources',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.commands',
'venv.lib.python3.6.site-packages.pip-9.0.1-py3.6.egg.pip.operations'],
url='',
license='',
author='',
author_email='',
description=''
)
The period in python3.6 is causing problems because when I run python setup.py develop I get the following error:
error: package directory 'venv/lib/python3/6/site-packages/PyQt5' does not exist
I'm not sure how to go about fixing this? If I simply change the python3.6 to python36 it just further breaks everything. How do I fix this?
Project view:
Project structure:

Related

setuptools "cannot find -lglfw"

I'm trying to make a python c++ extension using setuptools and I'm using glfw in my c++ project.
Here is what my setup.py looks like:
from setuptools import setup, Extension, find_packages
module1 = Extension('nerveblox',
sources = ['main.cpp', 'src/nerveblox_VM.cpp'],
include_dirs=["include", "lib/glfw/include"],
#extra_link_args=[ "-lm", "-lGL", "-lGLU", "-lglfw"],
library_dirs=["lib/glfw"],
libraries=['glfw']
)
setup (
name = 'Nerveblox_python_test',
version = '1.0',
description = 'This is a demo package',
ext_modules = [module1],
install_requires=[
'importlib-metadata; python_version == "3.8"',
],
)
My code works fine as pure c++ using cmake. When I run the above script I get this error:
/usr/bin/ld: cannot find -lglfw: No such file or directory
I've just downlaoded glfw source, extracted it to lib/glfw on my setup.py's directory, then ran cmake . and make inside lib/glfw. It's .so and .a files are inside lib/glfw/src.

AWS cluster import own modules Import error in python

I want to run a python project on a remote server (AWS cluster).
In the project, there is a model ("model") in path project/folder2/model, in model.py I have df.write.parquet(parquetFileName).
In order for the salves to have that "model" from "folder2" I am using setup from setuptools.
This is my setup.py (path project/setup.py):
setup(
name='dataFrameFromSpark',
version='',
packages=['project/config', 'project/folder2', 'project/folder3'],
py_modules=['project/model1'],
url='',
license='',
author='....',
author_email='',
description=''
)
Before running main.py I type this line on the remote server:
python project/setup.py build && python project/setup.py sdist && python project/setup.py bdist_egg
The error:
ImportError: No module named folder2.model
It seems the slaves don't get the folders when I run the "write to parquet" code.
what can I do?

ImportError on python exe file

Using py2exe I create an exe version of my script with instructions I found here. The script compiles well and generates a dist and build folder each but when I run the program on the command line it gives this error. N.B the script works fine on my IDE environment, however I intend give a colleague the exe version.How can I fix this error?
Traceback (most recent call last):
File "tester2.py", line 4, in <module>
ImportError: No module named mechanize
here is the setup.py file:
from distutils.core import setup
import py2exe
setup(
console = ['tester2.py'],
zipfile = None,
)
You have to declare your dependencies.
This is my setup
setup(
executables=executables,
options=options,
name='bla',
version='0.3',
packages=[...],
url='',
license='',
author='',
author_email='',
description='', requires=['pandas', 'unidecode', 'click',
'xlsxwriter'] // you would have to add mechanize here
)
Have you added files to the build?
Pls have a look at include option in setup.py: exe built with cx_Freeze, PyQt5, Python3 can't import ExtensionLoader_PyQt5_QtWidgets.py and run
Also here's my solution to similar problem, how to add files to build and run them later: Python - create an EXE that runs code as written, not as it was when compiled

Custom logic in setup.py to change environment header

I have a Python package that I'm distributing on PyPI. I create a script called run_program1 that launches a GUI on the command line.
A snippet of my setup.py file:
setup(
name='my_package',
...
entry_points={
'gui_scripts': [
'run_program1 = program1:start_func',
]
}
)
Unfortunately, the run_program1 executable fails to when installed with Anaconda Python, with an error like this:
This program needs access to the screen. Please run with a Framework build of python, and only when you are logged in on the main display of your Mac.
This issue turns out to be a fundamental issue between Anaconda and setuptools:
https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/9kQreoBIj3A
I'm trying to create an ugly hack to change the environment in the executable that pip creates -- run_program1 -- from #!/Users/***/anaconda2/bin/python to #/usr/bin/env pythonw. I can do this manually after installing on my machine by opening ~/anaconda2/bin/run_program1 and simply replacing the first line. With that edit, the executable works as expected. However, I need to create a hack that will allow me to do this for all users who use pip to install my_package.
I am using this approach to insert custom logic into my setup.py file: https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/
class CustomInstallCommand(install):
"""Customized setuptools install command - prints a friendly greeting."""
def run(self):
print "Hello, developer, how are you? :)"
install.run(self)
setup(
...
cmdclass={
'install': CustomInstallCommand,
}, ...)
What I can't figure out is, what should I put into the custom class to change the header in the run_program1 executable? Any ideas of how to approach this?

Building and distributing python moduel using rpm

I am trying to build and distribute rpm package of python module for centos. I have followed following steps
created virtualenv and installed requires
in module added setup.py with install_requires.
then using python2.7 from virtualenv build package
../env/bin/python2.7 setup.py bdist_rpm
Now I got src, no-arch and tar-gz files in 'dist' folder.
foo-0.1-1.noarch.rpm, foo-0.1-1.src.rpm, foo-0.1.tar.gz
I tried to install package src-rpm using 'sudo yum install foo-0.1-1.src.rpm',
got error something like wrong architecture
Then I tried to install package no-arch, 'sudo yum install foo-0.1-1.noarch.rpm' it works smoothly.
But after running script, it gave some import error. here I expect to download that module automatically.
The last thing is I am using some third party library which is not on pip.
So I want to whole setup using virtualenv with required modules. So after installing rpm, user can run script directly instead of installing third party libs separately and explicitly.
Some above steps may sounds wrong, as I am new to this stuff.
Following is code in setup.py
from setuptools import setup, find_packages
setup(
name = "foo",
version = "0.1",
packages = find_packages(),
scripts = ['foo/bar.py', ],
# Project uses reStructuredText, so ensure that the docutils get
# installed or upgraded on the target machine
install_requires = ['PyYAML', 'pyOpenSSL', 'pycrypto', 'privatelib1,'privatelib2', 'zope.interface'],
package_data = {
# If any package contains *.txt or *.rst files, include them:
'': ['*.txt', '*.rst'],
# And include any *.msg files found in the 'billing' package, too:
'foo': ['*.msg'],
},
# metadata for upload to PyPI
author = "foo bar",
description = "foo bar",
license = "",
keywords = "foo bar",
# could also include long_description, download_url, classifiers, etc.
)
Also I am using shebang in script as,
#!/usr/bin/env python2.7
Note:
I have multiple python setups. 2.6 and 2.7
By default 'python' commands gives 2.6
while command 'python2.7' gives python2.7
output of `'rpm -qp foo-0.1-1.noarch.rpm --requires' =>
`/usr/bin/python
python(abi) = 2.6
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
When i install pakcage. script's shebang line (which is now '/usr/bin/bar.py') is getting changed to /usr/bin/python' But I exclusively want to run script on python2.7.
Thanks in advance

Categories