I have an old c++/python project that includes a python zip file "python27.zip". This zip file contains pyo optimized files.
I am trying to update python from 2.7 to the latest 3.7.1 (also updated the *.so lib file)
I did the next steps:
./configure --enable-shared --prefix=~/python-3.7.1/dist
make
sudo make install
I see that I have ~/python-3.7.1/dist/lib/python3.7 and it's structure is close to that I have in my old 2.7 zip.
Next I try to compile all the folder into pyo like:
python3.7 -O -m compileall .
It tells me that it requires Lib and Include (the headers) so I copied those 2 folders in that location too.
Doing python3.7 -O -m compileall . again inside dist/lib/python3.7 shows me
Listing './Lib/site-packages'...
Listing './Lib/sqlite3'...
....
and some errors like:
Compiling './Lib/test/badsyntax_future10.py'...
*** File "./Lib/test/badsyntax_future10.py", line 3
from __future__ import print_function
^
SyntaxError: from __future__ imports must occur at the beginning of the file
I don't see any pyo's inside. Also if I try to do the same against 1 file, like python3.7 -O token.py (no errors) and also no pyo inside.
Don't judge me strict, I agree that I can be wrong in understanding this compilation process.
I had to create my own tool since I had not found anything suitable for the compilation of all python modules into one location/archive.
This PY_COMPILE_HELPER is available on the github. It was tested only from ubuntu.
With this module you can:
Set input and output folder for the compilation
Output source will have the same structure as the input source
Set optimization level for binary files
Skip or include test modules
Compress compiled files into one archive
Clean previously compiled files from the cache
Usage example:
$ ./py_compile_helper.py ./Python-3.7.1/Lib ./out -z -c -o2
Related
i'm currently working on an ubuntu 18.0.4.5 machine and i've been trying to figure out the whole kernel debugging process.
I've stumbled upon the need to auto run GDB scripts along with the vmlinux file, particulary the script residing under /usr/src/linux../scripts/gdb/vmlinux-gdb.py.
I made sure the script ran on initialization with the vmlinux file and had the following error
gdb vmlinux
File "/usr/src/linux-hwe-5.4-headers-5.4.0-42/scripts/gdb/vmlinux-gdb.py", line 34, in <module>
import linux.proc
File "/usr/share/gdb/auto-load/gdb/linux/proc.py", line 15, in <module>
from linux import constants
ImportError: cannot import name 'constants'
After this error occured I checked the /usr/share/gdb/auto-load/gdb/linux directory to look for the missing file and only found 2 related files:
constants.py.in
Makefile
Inside the constants.py.in file was C code mixed with python and was commented that the build will take care of that.
The exact Makefile and constants.py.in files can be found here for reference: https://elixir.bootlin.com/linux/v5.4/source/scripts/gdb/linux/Makefile
https://elixir.bootlin.com/linux/v5.4/source/scripts/gdb/linux/constants.py.in
Trying to build for the first time resulted in this:
make: *** No rule to make target '/constants.py.in', needed by '/constants.py'. Stop.
After some trial and error (i'm not experienced in Makefile language) I copied constants.py.in to the / directory and tried to build again and recieved the following error:
make: *** No rule to make target 'FORCE', needed by '/constants.py'. Stop.
I don't understand what does that FORCE is, looks like some kind of makefile configuration but i can't find a reasonable explantion or patch, the same errors occur when trying to build anything under /usr/src/linux-.../
trying to understand how to fix the build process and eventually create the correct constants.py that is hopefully the last piece to making the vmlinux-gdb.py work during debugging
Running make scripts_gdb at the top level of the source tree will run through a few other Makefiles and eventually build constants.py. You'll see some make chatter like the following:
builder#localhost:/tmp/linux/linux-5.4.125$ make V=1 scripts_gdb
make -f ./scripts/Makefile.build obj=scripts/basic
...
make -f ./scripts/Makefile.build obj=scripts/gdb
make -f ./scripts/Makefile.build obj=scripts/gdb/linux
gcc -E -E -x c -P -Wp,-MD,scripts/gdb/linux/.constants.py.d ... \
scripts/gdb/linux/constants.py.in > scripts/gdb/linux/constants.py ;\
sed -i '1,/<!-- end-c-headers -->/d;' scripts/gdb/linux/constants.py
ln -fsn /tmp/linux/linux-5.4.125/scripts/gdb/vmlinux-gdb.py
After this completes,vmlinux-gdb.py will be usable.
Pandoc comes with several default templates, which are distributed with the pandoc package. However, if I write an application that uses pandoc as a library, those default templates don't get included in the binary. I can still use them on my machine:
module Main where
import Text.Pandoc (getDefaultTemplate)
main = getDefaultTemplate Nothing "latex" >>= print
This will print the default.latex template. However, it's not portable, since it really refers to a file somewhere on my system:
$ cd path/to/example/project
$ stack build
$ scp path/to/binary remote:remote/path
$ ssh remote:remote/path/binary
example: Could not find data file /home/Zeta/.stack/snapshots/.../pandoc-1.16.0.2/data/templates/default.latex
Since pandoc's debian package does not include those files, it's somehow able to embed them. And indeed, there is a flag -f embed_data_files. I've tried to enable it in the local stack.yaml:
extra-deps: [pandoc-1.16]
flags:
pandoc:
embed_data_files: true
But that didn't change anything, the compiled binary still complains about missing data files.
So, is there any way to automatically include pandoc's template files?
It turns out that pandoc injects its data files during its build via hsb2hs. Somehow that step failed during stack build I missed the error message.
Neither hsb2hs nor its main dependency processing-tools are part of stack's LTS, they're only in the nightly stackage versions. The following additions to stack.yaml fixed the problem:
# part of stack.yaml:
extra-deps:
- preprocessor-tools-1.0.1
- hsb2hs-0.3.1
- pandoc-1.16
flags:
pandoc:
embed_data_files: true
For those using Cabal, this is somewhat equal to
cabal sandbox init
cabal update
cabal install hsb2hs-0.3.1 && cabal install pandoc-1.16 -f embed_data_files
cabal install --dependencies-only
cabal build
Here's how I verified that the templates are actually included:
$ stack build
$ grep "usepackage\{hyperref\}" .stack-work/install/*/bin/example -a
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
$endif$
\usepackage{hyperref}
$if(colorlinks)$
\PassOptionsToPackage{usenames,dvipsnames}{color} % color is loaded by hyperref
That snippet is part of default.latex, so it's really included in the binary.
(Archlinux/Python3.5)
I'm working on a small Python3 project made up of only one Python file . With the help of tutorials like this one, I've created a Pypi package with the following commands :
$ python setup.py sdist bdist_wheel register -r pypi (ok, no error msg)
$ python setup.py sdist bdist_wheel upload -r pypi (ok, no error msg)
... and I thought I would juste have to write :
$ sudo pip install katal (ok, no error msg)
and then, e.g. :
$ katal --version
... in order to use it.
But the last command fails : there's no katal or Katal command; if I take a look at /usr/lib/Python3.5/site-packages/ , I only see the following files (no .py file have been installed !) :
/usr/lib/python3.5/site-packages/Katal-0.0.9.dist-info/DESCRIPTION.rst
/usr/lib/python3.5/site-packages/Katal-0.0.9.dist-info/METADATA
/usr/lib/python3.5/site-packages/Katal-0.0.9.dist-info/RECORD
/usr/lib/python3.5/site-packages/Katal-0.0.9.dist-info/WHEEL
/usr/lib/python3.5/site-packages/Katal-0.0.9.dist-info/metadata.json
/usr/lib/python3.5/site-packages/Katal-0.0.9.dist-info/top_level.txt
I've obviously forgotten something... But what ? My setup.py clearly defines where is the unique package of my project (=take everything but the test directory, including the katal sub-directory) :
packages=find_packages(exclude=['tests*']),
Any help would be appreciated !
in your setup.py, there is a section which is commented out:
...
##entry_points={
## 'console_scripts': [
## 'sample=sample:main',
## ],
##
...
This is where I would normally define an executable, please see this tutorial. You can also define a scripts argument to setup which works a little differently (and might match your use case a little better), but that is covered in the tutorial I linked to.
I'm working on a project and I'm using Cabal for management. I've specified directory of source files, modules, all the stuff. All my files have the same names as their corresponding modules, case is preserved.
I can do:
$ cabal configure
$ cabal build
without problems.
However, imagine I have a module Module in file Module.hs, and file File.hs in the same directory. Now, when I'm trying to load File.hs from Emacs for testing, I get the following:
____Could not find module ‘Module’
It is a member of the hidden package ‘ghc-7.8.3’.
Use -v to see a list of the files searched for.
Failed, modules loaded: none.
Full contents of File.hs:
module File where
import Module
How to make it find files of my project?
You can launch the REPL via Cabal like so:
# cabal repl
This is the same as running ghci, but will take into account any additional dependencies installed by cabal install your local or sandbox package repository.
You need to tell GHCi where to find your source files. For example, if your project directory is ./foo and you have your source files in ./foo/src you need to say (from your project directory):
:set -isrc
at the command prompt in GHCi. You will then have access to private members in your sourc file loaded with C-c C-l.
You also need to make sure that you haven't cabal installed your package, otherwise the package will be loaded, not the project source files.
I had the same problem, fixed it, and decided to write about my troubleshooting. This might help new people learning Haskell. Read on.
I was playing around with this example code.
http://zvon.org/other/haskell/Outputdirectory/getCurrentDirectory_f.html
Code:
import Directory
main = aaa "/tmp/FOO"
aaa ddd = do createDirectory ddd
setCurrentDirectory ddd
d <- getCurrentDirectory
print d
writeFile "aaa" "HELLO"
l <- getDirectoryContents d
print l
I noticed that they are using this package.
https://hackage.haskell.org/package/directory-1.3.6.2/docs/System-Directory.html
So I installed it with this commands:
cabal update
cabal install directory
Compiling the example code with ghc failed with this error message.
Could not find module `Directory'
Use -v to see a list of the files searched for.
|
4 | import Directory
| ^^^^^^^^^^^^^^^^
I was stuck for a while until I changed the import line to this:
import System.Directory
After this change ghc could compile successfully.
Conclussion: are you sure you are importing properly?
I am trying to build an xsreensaver module using the makefile. I downloaded the source from http://www.jwz.org/xscreensaver/, and read the hacking readme.
As my screensaver involves opengl and reading of images, I'm trying to compile the 'photopile' screensaver.
I've run the following
$ cd xscreensaver-5.29
$ cd hacks
$ cd glx
$ make photopile
After running I get the following output errors
cc photopile.c -o photopile
photopile.c:38:23: fatal error: xlockmore.h: No such file or directory compilation terminated.
make: *** [photopile] Error 1
The referenced file is in the "hacks" root folder rather than the "glx" folder. I realize it would be simple enough to just copy that needed file to "glx", but the "xlockmore.h" file is not the only file that its trying to find that is not in the current directory.
It is also looking for "yarandom.h" in the "../../utils" folder.
I'm assuming the makefile was made correctly, and that I am doing something wrong with regards to calling the
make photopile
option from within the "glx" folder.
I'm still learning makefiles and would rather not modify it (or the directory structure by copying header files) anymore than the directions say to.
Any advice?