I am following a very simple tutorial for google app engine and at a point, after having installed Google sdk for python, it is asked to deploy the hello world app using the command from windows CMD:
>dev_appserver.py helloworld
My problem is: when I type this command, my Pycharm automatically pop up and open a tmp folder containing dev_appserver.py, as if I wanted to edit the file. I think that, when pycharm is installed, it forces a redirection of every command of the form >test.py to open the corresponding file in pycharm instead of executing the command.
What can I do to get rid of this?
Fixing the file association problem means removing the .py file association (likely created at pycharm's installation), which depends on your Windows version.
This official suggestion can be applied to several Windows versions.
For alternate solution search for "file association remove delete" and your Windows version, plenty of advice out there.
Note: after removing the association you'll need to manually select the application to use when you actually want to edit a .py file (which is not a big deal for one which typically opens the files from pycharm project windows).
Related
I have been using PyCharm since I began learning Python because of its amazing UI that helped me learn a great deal about the language. As I progress into more advanced projects, I am beginning to prefer using a text editor / command line combo so that I can build my own venv's and have better access to source control. My question is, how does PyCharm manage custom local packages that I created so that I can import them wherever I want in the directory? For instance a project that I have built exclusively in PyCharm that runs will raise numerous import errors when trying to run that same project in VS code, or even a command line shell (yes I did have the PyCharm created venv activated before running on both attempts). For further examples, here is the project structure I am confused about:
RootDirectory
package_1_folder
__init__.py
pckg_1_class.py
program_using_pckg_1_folder
class_using_pckg1class.py
venv
The above structure has no issues being imported and used in PyCharm, however VS code / Sublime when used with command prompt / gitbash will raise either an ImportError or a ModuleNotFound error. I have even gone as far as adding the desired packages to my laptops windows PATH, using sys.path.append (I know this is not good practice I was only trying to get it to work), and even modified the .pylintrc file with the project path with no success. Any help explaining why these errors are happening would be greatly appreciated :)
NOTE:
I have been able to use the packages in VS code as long as the program importing the module is located at the root directory level, but not in its own folder in the root directory. Again, this statement WILL work in PyCharm, I just want to know how PyCharm is able to achieve this.
After numerous attempts to locate how the system was keeping tack of module within the IDE, I found that my answer was not visible from the IDE. I found a .idea folder in my root directory that contains a few .xml documents that manage the directory including where to read modules from.
I installed python 2.7.13 and the google original App Engine SDK for PHP. I created my first project on google console and When I am trying to deploy the project file from cmd using
appcfg.py -A *project-id* update *project-folder*
Instead of running, its just being edited in chrome. Please refer attached picture chrome editing appcfg.py
you are probably running Windows and have probably wrongly associated your .py files with Google Chrome (like it is associated to .html files)
Chrome acts as a text viewer in that case.
Either reinstall python (to fix associations, that would be the best thing to do, python has a "repair" option when running the installation, no need to uninstall/reinstall) or remove your user registry key:
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
which must contain something wrong like:
#="\"C:\\Programs\\chrome.exe\" \"%1\"
and let system file associations take over.
or as a final workaround, if you cannot, just use python prefix to force python execution instead of relying on file associations:
python appcfg.py -A *project-id* update *project-folder*
(python must be in the path, and appcfg.py must be in the current directory or in PYTHONPATH)
note that the shebang #!/usr/bin/python doesn't help here (on Linux it would have helped)
Another way to repair associations manually is given in another answer of mine
I installed python 2.7.13 and the google original App Engine SDK for PHP. I created my first project on google console and When I am trying to deploy the project file from cmd using
appcfg.py -A *project-id* update *project-folder*
Instead of running, its just being edited in chrome. Please refer attached picture chrome editing appcfg.py
you are probably running Windows and have probably wrongly associated your .py files with Google Chrome (like it is associated to .html files)
Chrome acts as a text viewer in that case.
Either reinstall python (to fix associations, that would be the best thing to do, python has a "repair" option when running the installation, no need to uninstall/reinstall) or remove your user registry key:
[HKEY_CLASSES_ROOT\Python.File\shell\open\command]
which must contain something wrong like:
#="\"C:\\Programs\\chrome.exe\" \"%1\"
and let system file associations take over.
or as a final workaround, if you cannot, just use python prefix to force python execution instead of relying on file associations:
python appcfg.py -A *project-id* update *project-folder*
(python must be in the path, and appcfg.py must be in the current directory or in PYTHONPATH)
note that the shebang #!/usr/bin/python doesn't help here (on Linux it would have helped)
Another way to repair associations manually is given in another answer of mine
I am doing an application in Excel and I'd like to use python language. I've seen a pretty cool library called xlwings, but to run it a user need to have python installed.
Is there any possibility to prepare this kind of application that will be launch from a PC without Python?
Any suggestion are welcome!
A small workaround could be to package your application with cx_freeze or pyinstaller. Then it can run on a machine without installing python. The downside is of course that the program tend to be a bit bulky in size.
no. you must need install a python and for interpreting the python function etc.
It is possible using xlloop. This is a customized client-server approach, where the client is an excel .xll which must be installed on client's machine.
The server can be written in many languages, including python, and of course it must be launched on a server that has python installed. Currently the .xll is available only for 32 bits.
This might not be exactly what you're looking for (i.e.- "without python"), but you could ship it as a virtualenv .zip folder with all the necessary packages and respective python installation included in the folder... and also include a run.command bash executable inside the folder that the user can click on to run your program. You'll have to tell the user (inside a README.txt or something) how to enable the executable... For a particular application mine looked like...
Please complete the following steps after installation of MyApplication.zip:
Step 1: Move the MyApplication folder to your Desktop.
Step 2: Open your Terminal in Go then Applications then Utilities.
Step 3: In the Terminal, paste cd ~/Desktop/MyApplication
then press Enter.
Step 4: Then, paste chmod +x run.command
then press Enter.
From now on, clicking the “run” file in MyApplication will run the application.
If clicking the “run” file still doesn’t work, then do…
Click Ok on the popup then Open System Preferences then Security & Privacy
then Click on Open Anyway button then Click Open button on the popup.
NOTE: Please do not move or delete the MyApplication folder, or any of its files.
Then my run.command executable looked like the following:
cd ~/Desktop/MyApplication
PATH=$PATH:$HOME/Desktop/MyApplication/lib/python2.7/site-packages:$HOME/Desktop/MyApplication/lib/python2.7/site-packages/aeosa:$HOME/Desktop/MyApplication/lib/python2.7/lib-dynload:$HOME/Desktop/MyApplication/lib/python2.7/lib-old:$HOME/Desktop/MyApplication/lib/python2.7/lib-tk:$HOME/Desktop/MyApplication/Extras/lib/python:$HOME/Desktop/MyApplication/lib/python2.7/plat-mac/lib-scriptpackages:$HOME/Desktop/MyApplication/lib/python2.7/plat-mac:$HOME/Desktop/MyApplication/lib/python2.7/plat-darwin:$HOME/Desktop/MyApplication/lib/python2.7:$HOME/Desktop/MyApplication/lib/python27.zip
source bin/activate
python main.py
Three things are important here:
1) In run.command, I first change directory into the virtualenv I created for this project. I'm not trying to be dynamic here, since this is all just a quick hack of a solution, so as part of the README.txt, I simply tell the user to put the folder they downloaded onto their desktop. Otherwise, the cd command wouldn't work.
2) I set the client's PATH variable, separating entries with colons. You can see a list of the paths you'd need using a quick check on your computer...
import sys
for path in sys.path:
print path
3) I then call source bin/activate to activate the virtualenv.
4) I then execute my main.py file, which is in the top level of my virtualenv, along with run.command.
5) I only wrote this bash file for Mac OS X, so I don't know how it would translate to windows PCs. I think the only thing that'd change is that the path literals would need to use backslashes instead of forward slashes, but again, I haven't done this for windows so I'm uncertain.
Read more about setting up a virtualenv here: https://virtualenv.readthedocs.org/en/latest/index.html
Finally, note that you will not be able to send your final, working .zip folder over most email services, since they tend to prevent people from sending executables back and forth, so you'll have to use a service like Dropbox or something to send it to people.
I am just at the very start of what I think is gonna be a long journey exploring the world of applications in Google App Engine using Python.
I have just downloaded Python 2.6.4 from the Python official website and installed it on my computer (I am using Windows XP). I also downloaded the App Engine Python software development kit (SDK) (from this page) and installed it, too. Both of these steps were suggested on the second page of Google App Engine's Getting-Started Guide.
However, when I moved on to the third page, which is titled as "Hello, World!", I ran into a sort of complication. It is written there:
"Create a directory named helloworld.
All files for this application reside
in this directory. Inside the
helloworld directory, create a file
named helloworld.py, and give it the
following contents..."
I am kind of puzzled here: How do I create a .py file? Is it like I need to create a notepad file (.txt) and name it helloworld.py (when I did so, it didn't change into any different file of any different, but rather stayed an ordinary .txt file) or should I somehow create that file using Google App Engine Launcher that I have installed?
When you downloaded and installed Python, you also installed IDLE. You can use this to easily write, run, debug and save .py files with syntax highlighting. To get started, just open IDLE, and select File -> New Window.
A .py file is a text file containing Python syntax. Use your favourite programming editor, or even NotePad.
Regarding your second problem, there's an option in Windows Explorer about hiding file extensions. Make sure it isn't checked -- you might well actually have renamed your file helloworld.py.txt but only seen helloworld.py
You will need a better editor than Notepad. With Notepad, use Save As..., and type "helloworld.py" in the dialog, including quotes so that the file extension is .py instead of .txt
I am kind of puzzled here: How do I create a .py file? Is it like I need to create a notepad file (.txt) and name it helloworld.py?
I'm not on windows, but thats how it works on other operating systems: Create a file with an editor, then save as ...
ps. and .py is the extension (like .docx, .bat, ...), but it's just a convention (although a highly recommended one) ..
pps. heard the http://www.e-texteditor.com/ has more capabilities than notepad ..
You have to be aware that the ending signifies recognition of files, not content. Name a file .py simply hints to the user (and the GUI) that it most likely is a python file.
That being said, python files are merely text files. You can simply create a text file with Notepad (or your editor of choice) and rename the ending to .py and work from there. Most modern editors will also highlight the syntax based on file endings.