I've installed SMOP via pip and it seemed to work fine. I have smop-script.py and smop.exe files in my python folder \scripts\ folder.
Let's say I have a matlab file called myMatlabFile.m located in C:\Users\MyMatlabCode. How do I use smop to translate that file?
The SMOP documentation only includes an example of opening a file contained in a \smop\ folder with a main.py and I don't have anything like that. Also, the github page doesn't say whether it works only with 2.7 or 3. or whatever.
I was hoping that this package would speed up my Matlab -> Python 3.6 conversion, but if there are better translators out there now please let me know that too/instead.
I just tried using to convert a matlab file with SMOP and it worked. I installed the software using pip in Anaconda Prompt environment.
pip install smop
After the installation I had the 0.41 Version.
I copied the file that I wanted to convert in the folder where I ran the pip code in the Anaconda Prompt environment.
Then I used the code smop and the file name .m and got a file .py in the same folder.
smop VI.m
Using smop is not different from the other command
line tools. First, obtain the sources. Download, clone, tar, wget, or
whatever works for you. Let's call the directory containing setup.py
the root directory. Change directory to that one. Now install smop
> pip install .
Let's see if it works:
> smop -V
0.40
Yup, it does.
Let's see the docs:
> smop | more
At last, the translation itself.
If you have a bunch of Matlab m files, named foo.m, bar.m , bzz.m and you want to translate these files to python you type
> smop foo.m bar.m bzz.m
Related
Trying to make use of this package: https://github.com/microsoft/Simplify-Docx
Can someone pls tell me the proper sequence of actions needed to install and use the package?
What I've tried (as a separate commands from vscode terminal):
pip install python-docx
Git clone <git link>
python setup.py install
After the installation has been successfully completed I'm trying to run from VS Code terminal the file in which I've pasted the code from readme's "usage" section:
import docx
from simplify_docx import simplify
# read in a document
my_doc = docx.Document("docxinaprojectfolder.docx") //I wonder how should I properly specify the path to file?
# coerce to JSON using the standard options
my_doc_as_json = simplify(my_doc)
# or with non-standard options
my_doc_as_json = simplify(my_doc,{"remove-leading-white-space":False})
And I only get
ModuleNotFoundError: No module named 'docx'
But I've installed this module in the first place.
What am I doing wrong? Am I missing some of the steps? (Like init or smth).
Vscode status bar at the bottom left says that I'm using python 3.8.x, and I'm trying to run the script via "play" button.
python --version
Python 3.6.5
py show's though that 3.8.x is being used.
Thanks
Amin sama was right - that was indeed an environment issue.
Looks like modules were getting globally installed in an older python folder. Different from the python which runs when you try to run python file. So I had to uninstall the older python.
After that
py --version
and
Python --version
Started to show the same version unlike before.
So, the sequence
1. Opened a fresh folder within VS Code
2. git clone <git link to repository from github>
3. copied all the files from cloned repo to my current folder (or you can go one level down with cd command)
4. installed dependency: pip install python-docx
5. run setup.py from where you copied files: python setup.py install
6. Copy "usage" into a new file, for example run.py
7. Specify an absolute path to your file with double backslash.
8. Add strings to run.py to output the result in a json:
import json
with open('data.txt', 'w') as f:
json.dump(my_doc_as_json, f, ensure_ascii=False)
Run this file from the terminal opened in your project folder typing run.py or python run.py
It wasn't necessary to open >>> python console.
The problem is that your system doesn't have "docx" module.
to install docx module you will have to install docx.
steps to install:
1) open CMD prompt.
2) type "pip install docx"
if your installation is fresh it may need "simplify" module too.
Like any python package that doesn't come with python, you need to install it before using it. In your terminal window you can install if from the Python package index like this:
pip install simplify-docx
or you can install it directly from GitHub like this:
pip install git+git://github.com/microsoft/Simplify-Docx.git
I am using Tesseract OCR for my program and I am going to convert it into a single .exe file using pyinstaller. The problem is that in order for Tesseract to work, I need to reference the path to the program installed on my computer, like this: pytesseract.pytesseract.tesseract_cmd = 'E:\\Tesseract-OCR\\tesseract'
Since this is not just a separate library that can be imported, but a standalone program, I can't pass it to pyinstaller as an '--add_data' argument. How do I make a one-file executable then?
Assuming you're on Windows, I ran into this problem and think I solved it by compiling a static version of tesseract (which does not need to be installed) and including its path as a binary in the pyinstaller spec file.
Official compiling instructions here:
https://tesseract-ocr.github.io/tessdoc/Compiling.html#windows
Install MS Visual Studio 15 (with c++) and vcpkg and execute one of the following through command prompt:
for 64-bit:
vcpkg install tesseract:x64-windows-static
for 32-bit:
vcpkg install tesseract:x86-windows-static
The tesseract executable will be located a few subfolders within the vcpkg folder on your PC. With that file, you also need to download a .trainneddata file and place it within a folder called 'tessdata' in the same directory with the tesseract exe.
Create a pyinstaller spec file and edit the Analysis(binaries=[]) section to include the folder path where tesseract is located (if you're not using a subfolder for tesseract I think you'd need to add both tesseract.exe and the tessdata subfolder). I also changed inclide_binaries=True
Run pyinstaller and include the option --specpath 'yourspecfile.spec'
I haven't yet attempted to try it on a different PC, so haven't fully tested that it works as intended (I don't know anything about compiling c++, there may be additional files/links needed for tesseract that are still intact since I've only been testing on the build PC)
#Zstr33's answer is correct, but it lacked detail. Following instructions have been tested on Windows 10 64-bit. Link to official compiling instructions here: https://tesseract-ocr.github.io/tessdoc/Compiling.html#windows.
Steps:
Install Visual Studio. Make sure to install the below items:
Then, click on individual components.
Then, select the following.
You can add whatever other components you want, but those are the ones that are needed to compile tesseract into a static binary. Also, if you don't use English, click on the language packs tab and add the English Language pack, this is needed for vcpkg.
Follow the quick start guide for installing vcpkg, found here: https://github.com/microsoft/vcpkg#getting-started.
Navigate to where you copied the vcpkg directory, or add it to path. Then run: vcpkg install tesseract:x64-windows-static for 64-bit, or vcpkg install tesseract:x86-windows-static for 32-bit.
Go to place where you put the tesseract directory\tesseract_x64-windows-static\tools\tesseract for 64-bit, and place where you put the tesseract directory\tesseract_x86-windows-static\tools\tesseract for 32-bit.
To use with pyinstaller, using --onefile.
I built my application exe using Tesseract and EasyOCR with the following command, hope this helps.
python -m PyInstaller --paths "fullpath-to-custom-libraries" --add-data "C:\Program Files\Tesseract-OCR;Tesseract-OCR" --collect-all easyocr --onedir -w main.py
I did get it to run with Pyinstaller after all.
First, I needed to create 2 Hook files as described here:
https://github.com/jbarlow83/OCRmyPDF/issues/659#issuecomment-714479684
Then, when running the exe, I still got an error missing pikepdf._cpphelpers
To solve that, just add
from pikepdf import _cpphelpers
in your python file as described here:
How to fix a pyinstaller 'no module named...' error when my script imports the modules pikepdf and pdfminer3?
My Pyinstaller call looks like that:
pyinstaller --onefile appname.py --paths="C:\python\anaconda3\envs\appname\Lib\site-packages" --additional-hooks-dir="C:\coding\appname\Hooks"
since bundling everything up with pyinstaller could be a real pain, I did the following steps:
Imported Pytesseract in my script
created the Exe file with pyinstaller (without defining anything in my spec file)
bundled Tesseract-Ocr installer and my script.exe with an external installer creator.
So the final user will have both the tesseract installer and tesseract.
With the external installer you have a lot of freedom and you can also play with the path variable.
I tried with pyinstaller and ocrmypdf forever and did not get it to work. I ended up using Nuitka. Worked right from the start :-)
Use sth. like:
python -m nuitka --mingw64 --standalone --follow-imports yourapp.py
http://nuitka.net/doc/user-manual.html
There was a similar answer here somewhere already, just could not find it anymore to link to it.
this is my first time here, and I'm fairly new to python, so please let me know if you need more information. Thanks in advance.
I am running python 3 on Windows 7
I discovered my problem after I used pip install numpy. This works just fine. Then, when I try to use import numpy in the python shell I receive the ModuleNotFoundError: No module named 'numpy'. That's when I noticed that my default version of python was 3.6.1, despite having updated to 3.6.2 at some point. I still have both .exe setup files and when I run them it shows that I only have 3.6.2 installed. However, when I type python --version in the command line i get Python 3.6.1, even though Python36-32 is what i have in my path.
I think my question is how can I make sure I'm running the newer version of python as my default, or if need be, how can I get rid of the older version?
When you type python in cmd, it searches python command inside the directories in the environment variable named Path. Actually Path includes both python directory and python scripts directory. For example, in my computer, Path includes:
C:\Users\user\AppData\Local\Programs\Python\Python36
C:\Users\user\AppData\Local\Programs\Python\Python36\Scripts
pip is in the python scripts directory. Your Path can be wrong. You should check it. This link can help you. You should have one python directory and one python script directory in Path, just the version you need.
Also, you can call pip as a module:
python -m pip install numpy
This will install the package to the version which is in the Path, Python 3.6.2 in your situation.
If none of these works, I recommend you to uninstall(delete) Python 3.6.1, and try to use pip again. If pip doesn't work(or disappeares), you can read this or use get-pip.py to install pip to your computer again. Maybe, you can delete all python versions, and install the version you need, and of course, you should be careful about Path again.
EDIT:
I am not sure about your problem. Some informations are needed for a certain solution.
You can find the source of an executable(python or py in your situtation) with where command. Here is an example from my local:
where python
Output:
C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe
That means C:\Users\user\AppData\Local\Programs\Python\Python36-32\ directory is in my Path and when type python, cmd runs python.exe.
So, you can find out what are py and python exactly.
I am trying to install module using pip to run some ML-based python programs. Can somebody share your inputs on this. I tried googling but didn't find a solution... Any help would be appreciated. Thanks.
PS :- I already installed pip.
You could go to the path where python is installed for example something like this:
>>cd c:/users/demongking/python3/scripts
>>c:/users/demongking/python3/scripts>pip install pandas
you could also go to http://www.lfd.uci.edu/~gohlke/pythonlibs/ and download the wheel file (.whl) and then go to your download directory and from there you could do something like this:
>>c:/users/demonking/downloads>>c:/users/demongking/python3/scripts/pip
install modulename.whl
Alternatively you could download setup.py file and then go to cmd and change the directory to where the setup file is downloaded and then type
>>python setup.py install
Make sure to write full name of python version if you have multiple versions installed
Alternatively you could also do this:
>>py -version -m pip install modulename
where -version is your python version
if you want to recognize pip as a command directly by cmd you would have to change the PATH system variable
>>In Search, search for and then select: System (Control Panel)
>>Click the Advanced system settings link.
>>Click Environment Variables. In the section System Variables, find the
PATH environment variable and select it. Click Edit. If the PATH
environment variable does not exist, click New.
>>In the Edit System Variable (or New System Variable) window, specify the
value of the PATH environment variable. Click OK. Close all remaining
windows by clicking OK.
Path would be where pip is contained.For example it would be something like this
c:/users/demongking/python3/scripts/pip
If the problem is installing packages that require compiling code, there are alternatives like:
anaconda - a python distribution with an alternative package manager
gohlke - a collection of prebuilt windows packages for many python modules
I have a python 3 project on github, and I would like users to be able to download the zip file from the repository and run the program like:
$ python3 downloaded-file.zip
There is a __main __.py file and this works well when I zip the files up locally on my computer. When I download the zip from Github however, python is unable to run it with the error
File "downloaded-file.zip", line 1
PK
^
SyntaxError: invalid syntax
in the terminal. If the files are then unzipped, they can be run perfectly fine from the folder, but the .zip is easier for users to use. I would like it to be easy to download and run the python code and I'm not sure where the problem is arising.
Create a setup.py for your package, that is the recommended approach for python pkg distribution.
and If I were you, I will publish it so that others can do pip install pkg_name too.
This is not a elaborate answer, But, I think You have got the gist