How to use PyGObject module (gi) on Windows and PyCharm? - python-3.x

I have Python 3.8.1 installed and I've followed PyGObject tutorial to install the module.
I've installed MSYS2 64 bits and I certainly can import the gi module using MSYS2 terminal:
However, if I run Python from the cmd prompt or from PyCharm, it won't work:
I want to be able to run my project from PyCharm. What am I missing?

Look at the first lines that both Pythons produce. They are different.
The command-line python is a 64-bit version compiled with GCC.
The Python inside pycharm is a 32-bit version compiled with MSC.
Bottom line: Pycharm is not using the Python that you installed PyGObject in.
Edit
If you're not using the second Python instance, and nothing else on your system is using it, then it is indeed useless.
Having said that, 32-bit programs on windows have a limited adress space (2.5 GiB, IIRC). For data-science projects that might be a significant limitation these days. So I would stick to 64-bit programs these days, unless your PC has less than 4 GiB of RAM. Then it makes sense to run 32-bit software.
Another point is that I've seen reports here on Stackoverflow that Pycharm can interact negatively with Python programs that run inside it. Especially if you are running multiprocessing. So you should always test your code from a standalone Python, not from within Pycharm.

Related

Can't use python-snap7 on Windows

I can get Snap7 working on Linux but not on Windows using Pycharm. I get:
WindowsError: [Error 193] %1 is not a valid Win32 application.
I have tried Python 32 and 64 bit version using all combinations of the snap7.dll, the ones in the archives Win32 and Win64. I'm using Windows7 64-bit Professional. What's going on?
I have been working on a Linux system also with Snap7 for the past few months, to come over to Windows to also receive this issue. Only reason I haven't noticed this sooner is because I have been using the ClientDemo in the Snap7 Package.
I have tried the following:
Going back to older versions of Python (e.g. 2.7 where the documentation says its compatible)
un-installing and installing the packages (Both Python and Snap7)
There is only one thing I can clearly think of, and that it is the OS. Not sure if its all flavors of Windows 7 however. The documentation for the installation also states:
"Python-snap7 is developer for snap7 1.1.0 and Python2.7. It is tested on Windows (8.1 64 bit) and Linux, but it may work on other operating systems. Python 2.6 and Python 3+ may work, but are not fully tested yet."
Link: https://python-snap7.readthedocs.io/en/latest/introduction.html
So perhaps by chance, we are just unfortunate and that it does not work with this specific OS?

Compile python 3 script to standalone exe in Linux

Can a python 3 script be compiled in a linux environment in such a way as it can be run under Windows?
If so what compile tool? ie. py2exe or pyinstaller ect.
You're looking for cross-compilation, and the answer is no.
Can I package Windows binaries while running under Linux?
No, this is not supported. Please use Wine for this, PyInstaller runs fine in Wine. You may also want to have a look at this thread in the mailinglist. In version 1.4 we had build in some support for this, but it showed to work only half. It would require some Windows system on another partition and would only work for pure Python programs. As soon as you want a decent GUI (gtk, qt, wx), you would need to install Windows libraries anyhow. So it's much easier to just use Wine.
Can I package Windows binaries while running under OS X?
No, this is not supported. Please try Wine for this.
Can I package OS X binaries while running under Linux?
This is currently not possible at all. Sorry! If you want to help out, you are very welcome.
You may use Wine or the Windows Subsystem for Linux to attempt using PyInstaller to build stand-alone binaries for different operating systems, however, neither PyInstaller, nor Py2Exe, nor cx_freeze, nor any tool to my knowledge does this.
Effectively, in-order to do something like this, you would need a cross-compiler such as MinGW or VC++ for Linux, and integrate it into PyInstaller, which is very far outside of the scope of the project. It is much easier to use WINE or having a dual-boot system or multiple development computers.

Run python on Linux without python installed

Currently I'm using cx_Freeze to turn .py into .exe and this works fine with modules and everything, but I can't find any way to make it so it could run in Linux.
Is there any alternative for making it be able to run on Linux? Using something else other than cx_Freeze is fine.
Is there any way to compile it for Linux, while on Windows
From the docs
cx_Freeze works on Windows, Mac and Linux, but on each platform it only makes an executable that runs on that platform. So if you want to freeze your program for Windows, freeze it on Windows; if you want to run it on Macs, freeze it on a Mac.
You should try pyinstaller.
It supports creation of self-encapsulated python executables that work even when the python runtime is not installed.

How to set Python IDLE to use certain python version

I am using Windows 8.
Python version 2.7.3 have been installed on my computer together with another software.
Now I have installed python 3.3.5 and i want to use this version from now.
But everytime I run Python IDLE it runs version 2.7.3.
Even if I go to C:\Python33\Lib\idlelib\idle.pyw and run idle.pyw it runs with the 2.7.3 version.
I thought that every python version install its own IDLE so I am quiet confused here.
When I run Hello world program from the console it runs using the version 3.3.5 I have checked that.
So what I need to do is to run IDLE using 3.3.5 version
Anybody knows what to do?
Each installation of Python comes with its own respective version if IDLE. I suggest you explore your Python installation folder, and find the version of IDLE you're looking for and create a shortcut to it, or add it to your environment variable list, so you can invoke a specific version from the command line.

Cross-compile Python in Ubuntu to run on Windows

I need to compile a python script for a project. I am programming it in my Linux(Ubuntu) environment, and I need to have the finalized product be a .exe file to run on windows.
--It needs to be compiled so that the windows machine receiving it doesn't need to have a python environment installed on it.--
I know pyinstaller can compile scripts into executables, but it doesn't do cross-compiling.
An older version of pyinstaller does, but it only supports python2.6
The problem is, I need python 2.7 or 3.+ for my project.
Is there a program I can use to accomplish this, or maybe a workaround... something?

Resources