I have been trying this for hours now, but cannot seem to get this right. I am trying to download Pocketsphinx for use of command recognition in Python.
So first thing I did was attempt to install SphinxBase, which is required for Pocketsphinx to work. So here we go. I downloaded the files, the tar.gz zip. I followed the instructions in the README document in order to install on windows.
To compile sphinxbase in Visual Studio 2010 Express (or newer):
1, unzip the file.
2, rename the directory to sphinxbase
3, go into the sphinxbase folder and click sphinxbase.sln
4, in the menu, choose Build -> Rebuild All -> Batch Build -> Build
I have never used visual before, but it seemed pretty self explanatory. First thing I did was unzip and rename. Next up I opened the SLN project in visual, selected all 6 projects, the Files>Build Selection. It build with all 6 projects succeeding. Great, that's done. Now was that really all? I had to do?
Next up was PocketSphinx. I downloaded the tar.gz again, and basically did the same process.
* load pocketsphinx.sln in pocketsphinx directory
* compile all the projects in PocketSphinx
All builds succeeded in being built. So... done, right? After this, I am lost. Most tutorials stop here and do not actually go into using Pocketsphinx in other languages. I need to be able to use it in Python.
So I did some digging around and found a setup_win32.py file under pocketsphinx/python. I tried to run this in the command prompt but go multiple errors. Now I am running windows 64 bit, but could this cause this issue?
http://hastebin.com/japobecusi.tex
So all in all, I just need help getting this to work with Python. I am very inexperienced in these things currently. Thanks
One more thing, I am considering switching to my Ubuntu Linux partition in order to almost make it easier on myself. Most programs, including this one, seem to only use windows 32, like 64 is unacceptable apparently. So would it benefit me to move over to a Linux platform to work in Python? Would it be easier?
Thanks for any help in advance.
It is not that trivial to build python with swig on windows. You can just pick latest prebuilt binaries here:
https://pypi.python.org/pypi/PyPocketSphinx/12608
At the corresponding repository https://github.com/bambocher/PyPocketSphinx you can find more detailed manual on how to build it.
Please note that for latest features you need a latest pocketsphinx version from github/subversion repository, a packaged 0.8 is not going to work.
Switch to Linux is also a good idea.
Related
I have spent weeks looking for a way to turn my webcam (built into the computer) into a QR scanner using Python but nothing has worked.
In the first instance, I tried installing this software which supposedly would allow me to turn my camera into a barcode scanner, which could then use this video to decode the codes in python. I installed the scanner along with 'pywin32' which was supposedly the library I needed to use, but I couldn't get the two to communicate as my computer kept saying that pywin32 has not been installed (although it had).
Then, I moved onto using zbar/ pyzbar. I downloaded all of the modules that were recommended (I followed the instructions set out on here) but these each came with several more error messages. It was all to do with various libraries and modules not being installed - I've tried downloading PIL/pillow, pyqrcode and a number of other things that are supposed to work, but for some reason, don't.
I don't feel that I can provide any evidence of code as I haven't got any code to fix for this particular issue -- I am simply looking for anyone who may know of a way to transform an ordinary webcam into a barcode/qr scanner using python.
Assuming none of the libraries I need are installed on my computer at the moment, could someone please explain to me exactly which libraries I will need to download, where I can find them, and how I could use them to make Python communicate with my webcam?
This is for my A Level Coursework and the scanner is absolutely fundamental to the program; if anyone can provide me with a useful, understandable solution then I would be really grateful. I apologise if this question is still a little too broad - I am a complete novice to coding and after searching endlessly for hours to find a solution, I feel that this is my final resort.
I did a project on zbar a couple of years ago, and it took 6 months to get zbar working :)
Here's how I setup zbar:
Zbar python module does require zbar.exe. Go to http://zbar.sourceforge.net/download.html and click either ZBar 0.10 Windows installer if you have windows, or Linux builds. Run zbar-0.10-setup.exe and follow installation instructions.
The Zbar python module is available on pypi. That means a simple pip install zbar will install it.
To get .py examples of Zbar running, first download the source code for zbar (top link on http://zbar.sourceforge.net/download.html ), unzip the tar.bz2 file (use 7zip). Inside the unzipped folder there should be /examples. Inside the folder, you will find several examples (proccessor.py is a good one), which can be run just as you would normally run a python program.
I have tried portable python but the latest version is 3.2.5. (need 3.6+)
I cannot install libraries on it, even the get-pip.py doesn't work.
I'm trying to figure out how to make my project portable on windows systems that do not have python installed.
Also I want the minimum possible libraries(core python modules) to keep the project as lean as possible,
I would go with cx_Freeze - multiplatform module for freezing your Python script in a way that allows you to open it on other Windows machines even if they do not have Python installed. It got very nice and clear documentation also: http://cx-freeze.readthedocs.io/en/latest/ and works a bit better on Windows machines then alternative PyInstaller from my experience (which has interesting option of one-file-package, but in many cases leads to security warnings due to some dirty hacks used to obtain that feature).
However, it may not be enough if you are using some specific modules in your app, as for example matplotlib, dash, etc modules are very hard to pack correctly with Freezer.
I have found a solution to my own question after a couple of days.
I did not want to create an executable for my project but I wanted a portable python folder so that I can add libraries to it as and when I need.
The recent version of portable python is WinPython.
I had to delete some unnecessary files out of it though.
It's size is about 77 mb after extracting
https://winpython.github.io/
https://sourceforge.net/projects/winpython/files/WinPython_3.6/3.6.5.0/WinPython64-3.6.5.0Zero.exe/download
I don't even know the right way to put my question but i will try my best.
I downloaded (Python-3.4.2.tar) the source code of a python interpreter from www.python.org
I extracted the files(using 7-zip).
Now lets say i latter want to use the unziped/extracted fies to create an installer i.e put it in a form that i can double click and Python-3.4.2 will be installed in my computer.
i guess it is called creating a build distriution.
I know i can just download Python-3.4.2.exe from the site and install right away but i want to know how it goes from being source code to becoming something one can install.
Here's a starting point for compiling:
https://github.com/python/cpython/blob/2.7/PCbuild/readme.txt
I was able to compile 2.7.13 with:
cd PCBuild
cmd /c get_externals.bat
cmd /c build.bat -e --no-tkinter "/p:PlatformToolset=v100"
3.4 may require a later compiler.
Here's how to build an installer:
https://github.com/python/cpython/blob/2.7/Tools/msi/README.txt
For building the CPython python interpreter from source, you'll want to have a look at the instructions at https://docs.python.org/devguide/
These instructions probably also (somewhere) contain the steps to produce a Windows installer, which seems to be done with some tool called PCbuild.
Basically, I think what you are asking is how you can distribute the Python runtime along with your program. The process is pretty simple. First, you may want to take a look at Python's distutils. Secondly, you will need to distribute the Python runtime. Python is currently released within installation binaries for pretty much every major operating system. You have the option of compiling target system(s) yourself in order to make Python silently install.
You will then need to decide where you want the files to go. Most people don't like this sort of behavior, so I recommend putting the files in your programs directory. Shortcuts, system variables, et cetera will need to be looked into.
As another option you can consider porting your script(s) to Jython, as most people tend to have at least the Java runtime. In the process of porting your code there is a way of constructing Java .class files with Jython when coded a certain way. They can then be placed into an executable Jar file. Easy peasy, but I haven't tried this myself, to be honest.
If you want to stick with pure Python, the last hurtle is putting everything in one file. There are plenty of tools for that. I would try Github for starters. For bonus points you can always code your own self-extracting binary.
Post Script: With the title changed, I think you are looking for Creating Build Distributions. It is the second link within the Google results for the query "how to compile python installer". Further down the same page I found this gem.
This is probably a question that has a very easy and straightforward answer, however, despite having a few years programming experience, for some reason I still don't quite get the exact concepts of what it means to "build" and then to "install". I know how to use them and have used them a lot, but have no idea about the exact processes which happen in the background...
I have looked across the web, wikipedia, etc... but there is no one simple answer to it, neither can I find one here.
A good example, which I tried to understand, is adding new modules to python:
http://docs.python.org/2/install/index.html#how-installation-works
It says that "the build command is responsible for putting the files to install into a build directory"
And then for the install command: "After the build command runs (whether you run it explicitly, or the install command does it for you), the work of the install command is relatively simple: all it has to do is copy everything under build/lib (or build/lib.plat) to your chosen installation directory."
So essentially what this is saying is:
1. Copy everything to the build directory and then...
2. Copy everything to the installation directory
There must be a process missing somewhere in the explanation...complilation?
Would appreciate some straightforward not too techy answer but in as much detail as possible :)
Hopefully I am not the only one who doesn't know the detailed answer to this...
Thanks!
Aivoric
Building means compiling the source code to binary in a sandbox location where it won't affect your system if something goes wrong, like a build subdirectory inside the source code directory.
Install means copying the built binaries from the build subdirectory to a place in your system path, where they become easily accessible. This is rarely done by a straight copy command, and it's often done by some package manager that can track the files created and easily uninstall them later.
Usually, a build command does all the compiling and linking needed, but Python is an interpreted language, so if there are only pure Python files in the library, there's no compiling step in the build. Indeed, everything is copied to a build directory, and then copied again to a final location. Only if the library depends on code written in other languages that needs to be compiled you'll have a compiling step.
You want a new chair for your living-room and you want to make it yourself. You browse through a catalog and order a pile of parts. When they arrives at your door, you can't immediately use them. You have to build the chair at your workshop. After a bit of elbow-grease, you can sit down in it. Afterwards, you install the chair in your living-room, in a convenient place to sit down.
The chair is a program you want to use. It arrives at your house as source code. You build it by compiling it into a runnable program. You install it by making it easier to use.
The build and install commands you are refering to come from setup.py file right?
Setup.py (http://docs.python.org/2/distutils/setupscript.html)
This file is created by 3rd party applications / extensions of Python. They are not part of:
Python source code (bunch of c files, etc)
Python libraries that come bundled with Python
When a developer makes a library for python that he wants to share to the world he creates a setup.py file so the library can be installed on any computer that has python. Maybe this is the MISSING STEP
Setup.py sdist
This creates a python module (the tar.gz files). What this does is copy all the files used by the python library into a folder. Creates a setup.py file for the module and archives everything so the library can be built somewhere else.
Setup.py build
This builds the python module back into a library (SPECIFICALLY FOR THIS OS).
As you may know, the computer that the python library originally came from will be different from the library that you are installing on.
It might have a different version of python
It might have a different operating system
It might have a different processor / motherboard / etc
For all the reasons listed above the code will not work on another computer. So setup.py sdist creates a module with only the source files needed to rebuild the library on another computer.
What setup.py does exactly is similar to what a makefile would do. It compiles sources / creates libraries all that stuff.
Now we have a copy of all the files we need in the library and they will work on our computer / operating system.
Setup.py install
Great we have all the files needed. But they won't work. Why? Well they have to be added to Python that's why. This is where install comes in. Now that we have a local copy of the library we need to install it into python so you can use it like so:
import mycustomlibrary
In order to do this we need to do several things including:
Copy files to their library folders in our version of python.
Make sure library can be imported using import command
Run any special install instructions for this library. (seting up paths, etc)
This is the most complicated part of the task. What if our library uses BeautifulSoup? This is not a part of Python Library. We'd have to install it in a way such that our library and any others can use BeautifulSoup without interfering with each other.
Also what if python was installed someplace else? What if it was installed on a server with many users?
Install handles all these problems transparently. What is does is make the library that we just built able to run. All you have to do is use the import command, install handles the rest.
I'm following Google's OR-Tools instructions and reading this instruction:
> "Then you can download all dependencies and build them using:
>
> make third_party"
What is this make command? Should I run it from Windows command prompt? Where is this third_party file located?
Sorry for this basic question. I'm new to this realm.
That page seems very clear to me.
Please make sure that svn.exe, nmake.exe and cl.exe are in your path.
You need to do exactly that. nmake.exe implements the make command, from the sound of things. As to where you should run this command, run it, as the page says, from the terminal in the Tools menu in Visual Studio.
NAME
make - GNU make utility to maintain groups of programs
SYNOPSIS
make [ -f makefile ] [ option ] ... target ...
Simply put make is a compilation tool, the Make command is a command used in Linux to 'make' all necessary recompilations. Make requires a configuration file. Once this file is constructed for your project, you usually type make to build the changed files.
Take a look at this link for some make examples.
http://linuxdevcenter.com/pub/a/linux/2002/01/31/make_intro.html
As per the link you provided, the instructions are straight forward:
Compiling libraries
All build rules use make (gnu make), even on windows. A make.exe binary is provided in the tools sub-directory; They are providing you with the make.exe, which means that in Windows you can use svn.exe to execute the following commands, just make sure you are within the path that includes the make binary.
If you do not find svn.exe, please install a svn version that offers the command line tool.
http://www.collab.net/downloads/subversion
Just execute the following commands to build the dependencies:
make
To compile in debug mode while in windows, use the following:
make DEBUG="/Od /Zi" all
If you need to clean everything and do it again, run:
make clean
This will clean all downloaded sources, all compiled dependencies, and Makefile.local. It is useful to get a clean state, or if you have added an archive in dependencies.archives.
Finally, to compile the library run:
make all
When everything is compiled, you will find under or-tools/bin and or-tools/lib:
some static libraries (libcp.a, libutil.a and libbase.a, and more)
One binary per C++ example (e.g. nqueens)
C++ wrapping libraries (pywrapcp.so, linjniwrapconstraint_solver.so)
Java jars (com.google.ortools.constraintsolver.jar...)
C# assemblies
Then we can edit the MakeFile.local
First off, download Python 2.7 and JDK 7, install them.
Edit Makefile.local to point to the correct Python and Java installation. For instance, on my system, it is:
WINDOWS_JDK_DIR = c:\\Program Files\\Java\\jdk1.7.0_02
WINDOWS_PYTHON_VERSION = 27
WINDOWS_PYTHON_PATH = C:\\python27
Afterwards, to use python, you need to install google-apputils.
cd dependencies/sources/google-apputils
c:\python27\python.exe setup.py install