I am working on a text adventure with python and the issue i am having is getting spyder to open a interactive cmd window. so far i have tried os.systems('cmd / k') to try and open this which it did but i could not get any code to run and kept getting an app could not run this file error. my current code runs off a import module that pulls the actual adventure from another source code file. how can i make it to where only one file runs and opens the cmd window to play the text adventure?
(Spyder maintainer here) Cmd windows are hidden by default because there are some packages that open lot of them while running code (e.g. pyomo).
To change this behavior, you need to go to
Tools > Preferences > IPython console > Advanced settings > Windows adjustments
and deactivate the option called Hide command line output windows generated by the subprocess module.
I found myself in a similar situation, developing code for a research group with heavy Spyder usage. I came up with this workaround to force usage of the vanilla Popen class regardless of whether or not it is run from Spyder (full disclosure I have not tested it very aggressively):
import subprocess
try:
from spydercustomize import SubprocessPopen
except ImportError:
SubprocessPopen = subprocess.Popen
else:
SubprocessPopen = SubprocessPopen.__bases__[0]
process = SubprocessPopen()
Related
I am currently using Atom to code in Python3 on my Mac and I have a package installed ("atom-python-run") which launches a terminal window with the command "python3 {path}" with 'path' being the current working directory with filename.py included. It opens just fine and runs perfectly, but the window doesn't open on top of my atom window but behind it instead. I have to click it every time to see the terminal window and it's really frustrating. I also hate using CMD+Tab to find it as well.
This is a bug in the package I'm using (I think) and I don't want to wait for them to fix it. Are there any methods in OS X to ALWAYS open Terminal on top of every other window? Or a third-party application? I can't find a solution to this problem anywhere online.
If you install the scripts package and use it, the output will be written to a window in the Atom application and will be shown at completion. Go to the Atom package page and search for the word script. You should get a hit on the "script" package. Install this package by just clicking on the install button and then open Atom and the python script you wish to run. Now in Atom go to the packages menu item and from that menu select "script". You'll be given several options, choose "run script" and your script should run showing the output in a window at the bottom of the Atom window.
I am using Python Enthought Canopy. Each time I initiate the editor, I have to change the working directory by typing the code:
import os
os.chdir('C:/Users/Name/Canopy/scripts')
This is quite tedious as the directories are all reset after I quit the editor and start again.
Is there a way that I can change the default working directory, or change the profile of Canopy such that each time the settings will be run before coding?
1) Canopy's GUI is not IDLE.
2) Since this is ipython and has access to ipython magics, you can just type cd ~/Canopy/scripts with no import.
3) But I'm guessing that you have at least one script open in the editor. So you might prefer to just keep the directory synced to the editor, see http://docs.enthought.com/canopy/2.1/quick-start/code_editor.html#change-directory
4) All of the above said, yes you can run arbitrary code on ipython startup. See Ipython Notebook: Default Initialization Python Code
I've been trying to get the Flask CLI to debug from within PyCharm with no success. I've tried the recommended procedures listed here. However, this doesn't work under Windows since flask.exe is an executable and not a script. Renaming flask.exe to flask does not work either. This causes the following exception:
Jetbrains has an active incident report in YouTrack for this, but there's been no activity done on it yet, with the Kanban State set to "Not On Board", so it looks like it's going to be sometime before the issue is addressed.
Any help would be greatly appreciated.
EDIT: Using Pycharm run works properly. Trying to run using the Pycharm debugger causes the exception
EDIT 2: Results after creating flask_debug.py file as recommended:
Firstly, rename flask.py back to flask.exe.
In PyCharm's Run Configuration dialog manually enter the full path to the Flask executable in the Script: text box. Don't use the browse button as it filters on Python scripts (.py files).
See screenshot. In this instance there is a virtual environment called "href" and the flask executable is in the Scripts sub-directory.
To use PyCharms's debugger create a file in the root say flask_debug.py:
from flask.cli import main
if __name__ == '__main__':
main(as_module=False)
Then setup PyCharm to run this script passing any Flask CLI parameters as required. See screenshot below showing Run/Debug configuration and the debugger stopped at a breakpoint.
Below shows Flask 0.12.2 quickstart app running under the PyCharm debugger and showing the defined environmental variable FLASK_APP.
In the latest version of PyCharm, there's an option to run by Module name instead of by file. Using "flask" as the module name works as well and doesn't require you to create a flask_debug.py file.
I'm attaching the screenshot of the working fileset and the Run/Debug Configuration for reference. This answer is thanks to the support provided by pjcunningham.
I made a virtualenv with tensorflow installed and I changed Python interpreter set to the location where the virtualenv is located at. When I ran the program, it gives the error:
ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory
I have the following lines written in my .bashrc file
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH
export PATH=${CUDA_HOME}/bin:${PATH}
Also, I found the libcudnn.so.5 file in the following path:
/usr/local/cuda-8.0/lib64
I encountered this error before I opened PyCharm and I did manage to install the correct cudnn version. The problem is, I can use
$ source [virtualenv_path]
to active the virtualenv and run python in terminal and everything works fine, no errors shown. The program also runs without error in Pycharm's terminal but it just gives me the above error whenever I click the run button. Could there still be something wrong with the environment variable? How do I fix it?
Unfortunately in pycharm you have to set CUDA_HOME and LD_LIBRARY_PATH inside the IDE. To do that go to the Run menu->edit configurations then choose your project. Then you click on the Environment Variables and add an entry for CUDA_HOME and LD_LIBRARY_PATH. When you have done that you can run directly from inside pycharm. I would also recommend setting the defaults to have these paths as well, so you don't have to do this for every project. Also it wouldn't hurt to make sure you have the interpreter from source [virtualenv_path] set while you are on this setting page. Let me know if you have trouble finding where to do this.
I've read this other Stackoverflow post: Pycharm environment different than command line, and it seems that the problem is that openning PyCharm in the normal way won't preserve the bash environment. The solution is to open PyCharm from the command line and everything works now. All you need to do is to open PyCharm using charm and everything works fine now.
I have searched a lot, but I didn't find the right solution for this question anywhere. I found the solution with my friends and I would like to share with you also.
If your Tensorflow works in terminal properly but doesn't work in Pycharm you have two solutions:
1- Open Pycharm from Terminal. For me:
pycharm-community
2- If you are using Unity, you need to edit .profile, because Pycharm doesn't preserve .bashrc: So, open a terminal and type:
gedit .profile
Then, add the following codes at the end of the opened file:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Save and exit. Now, you can work with Tensorflow in Pycharm without the necessity of opening the Pycharm form terminal.
I've downloaded pygame-1.9.1release.tar.gz from the Pygame website. I extracted and installed it and it's working fine in the command line Python interpreter in Terminal (Ubuntu). But I want to install it for some IDE, like PyCharm. How can I do it?
Well, you don't have to download it for PyCharm here. You probably know how it checks your code. Through the interpreter! You don't need to use complex command lines or anything like that. You need to is:
Download the appropriate interpreter with PyGame included
Open your PyCharm IDE (Make sure it is up to date)
Go to File
Press Settings (Or Ctrl + Alt + S)
Double click on the option that looks like Project: Name_of_Project
Click on Project Interpreter
Choose the interpreter you want to use that includes PyGame as a module
Save your options
And you are ready to go! Here is an alternate (I have never done this, please try to test it)
Add PyGame in the same folder as your PyCharm file (Your PyCharm stuff is always in
a specific file placed by you during installation/upgrade)
Please consider putting your PyCharm stuff inside a folder for easy access.
I hope this helps you!
For PyCharm 2017 do the following:
File - Settings
Double click on your project name
Select Project Interpreter
Click on green + button on the right side of the window
Type Pygame in search window
Click Install package.
Not I'm saying that the answers above won't work, but it might be frustrating to a newbie to do command line magic.
If you are using PyCharm and you are on a Windows 10 machine use the following instructions:
Click on the Windows start menu and type cmd and click on the Command Prompt icon.
Use the command pushd to navigate to your PyCharm project which should be located in your user folder on the C:\ drive. Example: C:\Users\username\PycharmProjects\project name\venv\Scripts.
(If you are unsure go to the settings within PyCharm and navigate to the Python Interpreter settings. This should show you the file path for the interpreter that your project is using. Credit to Anthony Pham for instructions to navigate to interpreter settings.)
HINT: Use copy and paste in the command prompt to paste in the file path.
Use the command pip install pygame and the pip program will handle the rest for you.
Restart you Pycharm and you should now be able to import pygame
Hope this helps. I had a fun time trying to find out the correct way to get it installed, so hopefully this helps someone out in the future.
I just figured it out!
Put the .whl file in C:\Program Files\Anaconda3
While in the folder, click on the blue File tab in the upper left corner of the Window Explorer (assuming you're using Windows)
Click on Open Windows PowerShell as administrator
Write or just copy and paste: py -m pip install pygame
It should start installing
Done!
I hope it works for you. I know it did for me.
I already had pygame installed with python38-32
since its working just fine with it. I used this version of python us my project interpreter.
1.File -settings
2.according to your settings look for project interpreter
3.click on your current project interpreter and click on the add symbol
4.choose system interpreter
5.select the python version thats works with pygame for you
6.Note: some versions of pygame don't work with some versions of python be sure
of what are you doing.
7.hope it works.