I've just started learning Python and have downloaded PyCharm and understand this is likely to be a very basic question but wanted to ask before I set off with a false sense of security.
I'm interested to know whether:
a) Simply opening but not running a .py file as a project in PyCharm IDE could be malicious.
b) Opening and running a .py file in the PyCharm IDE can be malicious
If not either, why not? Would the file need to be a .exe to do anything without PyCharm being involved?
Again, appreciate any help/insight you can provide.
So just opening a file in PyCharm will not harm any computer in any way.
But running code can do that, so I would be careful were you get the code which you want to execute. And it would be best if you understood the basic of the code you are running. Therefore you would be able to spot strange lines in your code.
A Python source file (like any other programming language) is just a plain text file, so until the instructions that are written in the file are evaluated (by the python interpreter in this case) the file itself cannot be in any way harmful.
Only once you run python myfile.py in a shell or by using an IDE like PyCharm the code is actually executed... at that point what happens depends on what is written in the file (which you can check before executing it).
Related
What happens when you turn a python file into an executable? Does it get encrypted? What happens to the imported files? Can you revert it back into a normal .py file?
So I have this python file, let's call this main.py. I also have another file, let's call it scrambler.py. The scrambler.py is an encryptor/decryptor file. So, I imported it to main.py. Then I will turn it into an executable file. Now, we don't want people to see the enryptor/decryptor file. So, can people who doesn't have the source code get the source code of the imported file? Because, from searching, I saw that some people can get the source code of the main code using pyinstxtractor.py. I haven't tried it yet, but can you also get the source code of the imported file? (also do comments get included? I mean they are useless to the program). So that's why, the ultimate question: What happens when you turn a python file into an executable?
The file that I use to turn a python file into an .exe is Pyinstaller and is it different for every converter?
I hope this is a valid question. Thanks in advance.
Pyinstaller essentially bundles a python interpreter along with your python code in a folder. This folder can be put into an installer (using something like inno setup) to be distributed so end users can use it like a normal exe program. It doesn't compile to another language or anything. So no, your code is not private and while you can make it difficult to find certain bits, it is not impossible.
As described here, it is possible to convert to C and to machine code, but pyinstaller won't do that by default for you. Also note that the python bytecode files, while not legible, are not completely uncrackable.
See: https://pyinstaller.readthedocs.io/en/stable/operating-mode.html
See here for more about the encryption option: PyInstaller Encryption --key
I'm extremely new to coding and have almost no idea what I'm doing. I am trying to send a (.py) to someone but they do not have any version of python downloaded. I am wondering if there is any way to send it as a different file but still have them run it as they click on it? Would really appreciate some feedback.
As you mention, if there is no python interpreter installed, you cannot run the .py file directly.
You can convert your .py to binary executable so it can be executed directly. You can use PyInstaller for this.
Alright just for context I'm an extreme newbie to python (around 15 minutes of experience).
My question is most likely a dumb one, but I'm gonna ask it anyways as I can't find anything about it elsewhere; Why can't I run the (very advanced) code below as a .py file? Using version 3.6 if it matters.
print("hello")
Thanks
Opening the python file will not cause it to execute.
Depending on your operating system (Windows, Mac, Linux) try opening a
command window and navigating to the file location of you python file.
Once you are in the directory (folder) of the python file that contains
the print statement run the following:
python myfile.py
Does that work?
Download and install
https://www.jetbrains.com/pycharm/download/#section=mac[Pycharm][1]
It is an IDE (Integrated Developer Environment). Pycharm will have what you need to write, save and execute python code all in the same application. There are others of course but Pycharm is as good as any to start with.
Good luck!
I wrote a program with Qt and I embedded a .py file in it to do some work.
On my computer which has the Python interpreter installed, the program can run correctly, but when I run it on my roommate's PC, which has NO Python interpreter installed, the program crashed.
The part which is written with Qt runs well but when I push a button to call .py to do some work, the program crashes.
I think the problem is that I haven't put the std library and some other key files of Python into the folder of my program, but I have no idea what files should I pack into it.
So if the problem is really what I thought, what should I do to solve it?
Namely, which files of Python should be packaged into a program to run on the PC with no Python interpreter ?
Thanks in advance.
------------update------------------
As for the code of Python, it's just a hello-world for test and learning. I copy the whole Python34 folder into the program and the question has been solved:). Though it may not be a right way, it works.
Python's documentation has a reference manual for the C/C++ API.
The file I believe you're referring to is Python.h, though I'm no expert on this. It's considerably easier to embed C than C++, and this gives some of the more simple examples. As far as I know, you shouldn't need to worry about the interpreter for compiling to an executable.
I am working on a project in PyCharm that involves extensive computations, with long runtimes.
I would like to do the following: I come up with a version of my code; then run it, then I edit the code some more; however, the run I started before still only uses the old version of the code (i.e. the snapshot at the point of running).
Is this possible in PyCharm?
I run my project by selecting the Run 'projectname' option from the Run menu.
I understand the run works by pre-compling the .py files to .pyc files stored in the __pycache__ folder. However, I don't know the following.
Will saving the file in PyCharm cause the .pyc files to be replaced by new versions? This is something I want to avoid since I want one run to only use one snapshot of the source tree, not multiple versions at different points of execution.
What if some python class is only needed, say, 20 minutes after the run has started. Will the .pyc file be created at the beginning of the run, or on-demand (where the corresponding .py file might already have changed)?
I use PyCharm in my classes. My experience is that the all the required code, including the imported modules, are compiled at runtime. If you change anything in that suite you need to start running from scratch for it to take effect.
I'm not a professional programmer so my experience is with small apps. I'd love to hear form an expert.