How to setup PyCharm for Shell/Bash scripts - python

I've been struggling for a long time now to get this running but I just couldn't do it. I am runnning PyCharm Professional on Win10 and I want to code and run Shell scripts, but I cannot get it to work. There is this Shell Plugin from Pycharm but there is just not enough documention for me to understand how it has to be setup.
How do I have to setup PyCharm in order to Run/Debug Shell scripts?
I tried changing the shell used by the Terminal to the WSL Ubuntu shell, which actually worked. Thus I can now manually execute the bash script via the terminal.
I also tried changing the Run/Debug configuration.
changed Run/Debug configuration
as suggesteed, changing the interpreter to bash.exe led to an error message.
interpreter changed to bash.exe
I tried bash.exe, ubuntu.exe and cmd.exe as shells for terminal, all of which threw a file not found error. As before executing it manually with the wsl path format(/mnt/c/..) works. manual execution
"file not found"-error

So I guess it was my misunderstanding in the end, that you can't really work with shell scripts like you do with python. meaning debugging etc and watching variables. I am trying to reduce my file shuffling code in bash anyways and try to stay mainly in python so there is now another motivation for that. thank you very much for helping me though.

Related

Activating virtual environment for django in command line versus activating it in the Atom terminal

I am having a hard time activating virtual environment, after I have created it.
The thing is, that when I try to activate virtual environment in command line, it works -
virtualenvironmentname\Scripts\activate
But when I try to run the same command in Atom, (I am using the Terminus package in order to be able to run the terminal inside Atom) I get this message -
File (path\activate.ps1) cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies
at https:/go.microsoft.com/fwlink/?LinkID=135170.
I was trying to run it by using slightly different commands such as -
activate virtualenvironmentname or activate (virtualenvironmentname)
, but it did not work.
I was further investigating a little more and I have found some clues, that I might need to change some script execution policies, but I am little bit afraid to do so, because I do not want to mess up my computer since I am just a beginner when it comes to system configuration.
Could anybody please tell me, how could I fix this problem? It would be really convenient for me to be able to run the virtual environment from Atom, since I will be writing my Python and Django lines of code there.
Thank You very much and I hope, that my description of the problem was somehow understandable.

System crashes each time i run python command in Terminal, how to get rid of /opt/miniconda3/bin/python?

please I need your help here!
My system crashes each time i run a python command in terminal. When i run something like python app.py, my Mac will crash and bounce, and reset.
In Terminal,
When i run python -V, it returns Python 3.7.6,
When i run python3 -V, it returns Python 3.8.5
When i run which python, it returns /opt/miniconda3/bin/python.
A moment ago, i was trying to build a standalone app, and turned on virtualenv. However no matter how hard i tried, i failed. Then i deleted the virtualenv folder in the app folder.
Perhaps during the development processes, in Visual Studio Code, i accidentally "linked" the virtualenv with the python interpreter 3.7 (/opt/miniconda3/bin/python), which was set as the default python system long ago (i can't even recall when and how). After the virtualenv folder deletion, i remember the interpreter had the word "cached" in the front of the python version. Somehow i turned on and off this and that, and restarted the app, i have get rid of the word "cached". But the system still crashes .
My Mac crashes now every time i run a python command in Terminal. Please help!
i even have tried update conda update conda, it says no such directory,
ofcoruse i then tried update miniconda, same answer.
You should remove it from your path.
To do so, check for the miniconda3 entry in the file named ~/.bashrc, ~/.bash_profile, and /etc/profile file and comment out the line:
export PATH=/opt/miniconda3/bin:$PATH
by preceding it with the # character.

Choosing specific python interpreter in the shell

I've been developing a set of scripts in PyCharm using C:/Python27/python.exe interpreter...
I'm creating a batch file and then running all of the scripts through this file from the cmd shell however the shell is not recognizing most modules because it is using the wrong interpreter (path for anaconda instead)...
How do I change the shell to use the C:/Python27/python.exe interpreter as default all the time instead?
I've tried looking this up but it all points to just adding the interpreter path, which I have... but the shell still uses the anaconda interpreter.
Any help appreicated
Take a look at : https://docs.python.org/3.3/using/windows.html#shebang-lines
Shebang lines at the beginning of scripts tells how a script should be executed.
Found a solution to my problem...
I needed to use:
set path=%path%;C:\Python27
This switched interpreter.
Cheers

os.system does not look the programs that are in my path

I have a problem when calling programs inside a python script. The programs that are giving me problems are those that I have installed manually on my computer and then added them to path on .bashrc file. The programs that where installed using 'sudo apt-get install some_program' don't give me any problem
The programs where added to my .bashrc file as the following way:
#path to fastqc
export PATH=$PATH:/home/bioinfor3/bin/FastQC/
#path to fastx-toolkits
export PATH=$PATH:/home/bioinfor3/bin/fastx/
Inside my PyCharm, I am using the os module to call those programs the in the below manner:
os.system('fastqc seq.fastq')
And I get this error
sh: 1: fastqc: not found
I guess it has something to do with the sh path or something, but I am not able to make it work
EDIT:
If Pycharm is launched from the terminal, it inherits the bashrc file with my personal paths and it works
Presumably this is happening because you have modified your login environment to adjust your PATH, but this updated path isn't seen by the shell that's running PyCharm, or PyCharm appears to be nullifying it somehow.
You should first of all verify that
os.system('/home/bioinfor3/bin/FastQC/fastqc seq.fastq')
operates as you would expect (no reason why it shouldn't, but worth checking).
It seems from this answer that by default PyCharm doesn't use bash for its shell but tcsh. Therefore it isn't seeing the setting you are enforcing on bash.

Getting Enthought Python IDLE to run code when shell is restarted

I'm running EPD and using IDLE for most of my coding. What I'd like to do is get IDLE to run a script to customize my environment whenever I restart the Python shell. I've tried reading all the various posts on customizing IDLE and the Python environment, and I've yet to see anything that addresses this specific scenario. Does IDLE or EPD IDLE (if there's any difference) have a particular module it's looking for when it restarts the shell, like usercustomize.py or sitecustomize.py? Has anyone accomplished this on their own? Any guidance is appreciated.
Upon startup with the -s option, IDLE will execute the file referenced by the environment variables IDLESTARTUP or PYTHONSTARTUP.
Check out: http://docs.python.org/library/idle.html#startup
Cheers,
Johannes

Categories