I need to write a python code which enables me to verify whether the received SSL certificate from a website is valid or not. the code snippet is gonna be executed in windows platform.
I've been using Editra to code python recently which is equipped with PyStudio plugin. I got confused if it's a possible idea or not.
Does anyone have any idea how to make it work?
If you want to distribute a Python script on Windows, (which doesn't have Python installed by default), you can use py2exe. py2exe converts your Python script into an executable that Windows users can run without them needing to install Python.
Consider Python XY if you are concerned about a good Python installation under windows including a lot of helpful, preconfigured packages.
Assuming it's just a plain script you want to execute, you can do so by invoking the python runtime in the command line, and issuing it to execute the script.
For instance:
python myscript.py
Related
I am using PyCharm to develop a python project, which uses an external library called win10toast. I have installed win10toast using PyCharm. However, when I tried to run the .py file using cmd (i.e Externally running the python file), an error shows up:
ModuleNotFoundError: No module named 'win10toast'.
I have python 3.6.4. I installed win10toast using PyCharm.
from win10toast import ToastNotifier
I expect the program to run without any error, but currently I am getting the ModuleNotFound error.
Python can be tricky to run properly because it is sensitive to where you installed your dependencies (such as external libraries and packages). If you installed Python to one directory, but accidentally installed the external library to another directory, when you run your .py program, it will be unable to call from the external library because it doesn't exist in the same library that Python is running from.
Lookup where you installed Python on your computer and then find where you installed the external library. Once your find where you installed the external library, move its entire package content to the same directory where Python is installed. Or better yet, reinstall the external library with pip into the same directory as Python.
If you're on Mac, Python and its related dependencies are usually stored somewhere in /User/bin. If you're on Windows, it will be stored somewhere in your C:// directory (possibly somewhere in C:\Users\username\Local\AppData). If you're on Linux, it will be stored somewhere in /usr/bin. Whatever you do, don't move Python from wherever it is because sometimes that can mess up your system for certain operating systems like Mac, which comes with its own version of Python (Python 2.7 I believe, which is outdated anyway).
Lastly, you may have two different versions of Python on your computer, which is common; Python 2.7 and Python 3+. If you wrote your program in one version, but ran it from the other, the external library can only be called from whichever Python version you installed it to. Try running your .py program with python3 instead of python (or vice versa) and see what happens. If it works with one python version over the other, that tells you that the external library is installed in the other version's directory.
That should solve your issue.
I would suggest that you not use PyCharm to install packages, at least not
if the result deviates in the slightest from doing a "pip install" at the command line. I see no reason to involve PyCharm in configuring Python installations. It's just asking for trouble.
I admit that I'm not familiar with the practice I'm suggesting you avoid. I've been using PyCharm since pretty much the week it came out (was an avid user of the IntelliJ Python plugin before that), and have never once considered doing anything but installing Python modules at the command line. That way, I'm sure right where those modules are going (into which base Python install or venv). Also, I know I'm doing all that I can to minimize the differences that I might see between running code in PyCharm and running it at the command line. I'm making my suggestion based solely on this practice having never gone wrong for me.
I have multiple base Python versions installed, and dozens of venvs defined on top of those. PyCharm is great at allowing me to indicate which of these I want to apply to any project or Run/Debug configuration, and utilizing them seamlessly. But agin, I administer these environments at the command line exclusively.
I still experience issues in switching between the command line and PyCharm in terms of one module referencing others in a single source tree. My company has come up with a simple solution to this that insures that all of our Python scripts still run when moving away from PyCharm and its logic for maintaining the Python Path within a project. I've explained the mechanism before on S.O. I'd be happy to find that if anyone is interested.
The library win10toast installed in the directory: YOUR_PYCHARM_WORKSPACE\PycharmProjects\YOUR_PROJECT_NAME\venv\Lib\site-packages
but when you are running your program using cmd, pycharm interpreter uses site-packages directory that you installed python at there. for Ex: C:\Python27\Lib\site-packages
So, you can install the win10toast library to this windows directory using pip.
Is it possible to use pyWin32 without installing it?
I would like to include it into python's interpreter folder.
I have managed to use Python interpreter without installing it (simply installing it and copy&pasting installed directory into my product).
I need also the same with pyWin32.
My objective is:
Client receives a folder with a script (batch) which will run python program in a console. The client does not have to install python, pywin32, nothing. What he needs is to copy and paste my product and run the console-based program.
Is it possible?
My objective is: Client receives a folder with a script (batch) which
will run python program in a console. The client does not have to
install python, pywin32, nothing. What he needs is to copy and paste
my product and run the console-based program.
I would suggest something along the lines of using pyinstaller or any other python code to executable converter.
http://www.pyinstaller.org/
PyInstaller is a program that freezes (packages) Python programs into
stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD,
Solaris and AIX. Its main advantages over similar tools are that
PyInstaller works with Python 2.7 and 3.3—3.5, it builds smaller
executables thanks to transparent compression, it is fully
multi-platform, and use the OS support to load the dynamic libraries,
thus ensuring full compatibility.
To me it seems this would suit your/your clients needs quite well. Furthermore pyinstaller is easy to use.
I have a NodeJS web server (Express) locally that uses Python-Shell to fire off Python scripts (mostly scraper stuff using PyCurl). The Python scripts also use various modules that I have installed using pip. This all works locally with no issues, running Node v4.1.1 and Python 2.7.10.
Now, I need a server to run this setup on, and I'm cheap, so I really want to use Openshift, which I have used before for other Node-only projects.
My problem is that I need to work with Python, and while it is installed (v2.6 anyway), I can't do much with it. Pip is not installed at all, and I don't have administrative rights to install it. Easy_install seems to be present, but I get permission issues when trying to execute it (even just the test via "easy_install" with no parameters). I need pip to install several modules for my Python scripts.
I was able to follow the instructions here and get Python 2.7, setuptools, and pip all installed successfully, but they are only available by prefixing the path $OPENSHIFT_DATA_DIR/bin (which resolves to /var/lib/openshift/[my-id]/app-root/data/bin). So...
\> $OPENSHIFT_DATA_DIR/bin/python -V
Python 2.7.3
I can also successfully run my Python scripts if I prefix the python command with that path.
So my question is how can I either get python-shell to use that path for Python, or how can I update Openshift's environment variables so that the standard "python" command is pointed to my manually-built v2.7.3 executable?
I'm stumped, but I know next to nothing about Linux or Openshift's architecture specifically, so I'm hoping you guru's out there can help me out!
If someone ever has a real answer to this, feel free to post it up, but I ended up just abandoning Python altogether and re-wrote the scraper in Node using Cheerio. Much better!
I am writing a small python installer application that will run on linux. However, i don't know which Linux in advanced, so i cant write for any specific python version since i have no idea what is installed on the client computer, if any (do i? is there any thumb rule for python version preinstalled on a Linux machine?).
Is there a optimal way to install a local python version on a client's computer in some temporary directory, use it for the application run-time, than remove it when it is done?
Do you know the machines architecture? If so simply download the python version you want to install on the linux architecture on your server/box/your computer then compress it and upload it to a server somewhere. (or use the link on python.org)
then simply make a bash script to download it and uncompress it. Then install it using shell commands like make or cmake ./configure within the install directory
If you dont know the architecture or are trying to use it on some generic or other you could cross compile it using these cross compilers to cross compile python (or anything coded in c(/c++?))
http://pastebin.com/mxWqBvy8
Typically the general 'rule of thumb' for the python version would be python2.7.x
You could use Pyinstaller to "compile" your python (its origanally win) there is a linux version somewhere, fairly sure its as easy as pyinstaller test.py)
Removing it shouldnt be that hard, rm is universal everywhere
You can bundle your programs with Python itself without requiring the target machine installed Python Interpreter on it.
Check this out: https://wiki.python.org/moin/Freeze
I'm writing what is a relatively small desktop application, but I'm using several technologies/languages and not sure the best way to create a installer script.
I have a python script which uses tornado and scapy (which also requires pcapy), and have a kernel extension that needs to be installed.
This python script is executed and works in conjunction with a node-webkit (nw) app I'm writing. Any suggestions on the easiest way to ensure all of the dependencies are met, and properly installed without the user having to touch the command line? Using python setuptools or pyinstaller? Package it together with nw? Use OS X packagemaker? Writing a bash script? Should I distribute these dependancies with my actual app?
Are you using python2 or python3? Dependencies for scapy differ.