[Tutor] How can I open and use gnome-terminal from a Python script?

Jim Byrnes jf_byrnes at comcast.net
Sat Jul 12 03:29:57 CEST 2014


On 07/10/2014 09:23 AM, Jim Byrnes wrote:
> On 07/09/2014 04:16 PM, Walter Prins wrote:
>> Hi Jim,
>>
>> On 9 July 2014 14:43, Jim Byrnes <jf_byrnes at comcast.net> wrote:
>>
>>> On 07/09/2014 04:27 AM, Walter Prins wrote:
>>>
>>>> I forgot to mention I am using Linux (Ubuntu 12.04).
>>>>
>>>
>>> I am working my way through a book about breezypythongui which uses
>>> Python
>>> 3, hence virtualenv.  I found that each time I started to work with it I
>>> did the above 3 steps, I was just looking to automatic that
>>> repetitive task.
>>>
>>
>> In that case you should put these commands in your .bashrc file so it
>> gets
>> set up as your user's default.  (The .bashrc file is somewhat like DOS's
>> "autoexec.bat" file, if you're familiar with this, except each user has
>> their own .bashrc.)  You can also create a shell script that does this
>> for
>> you.  (You can install "virtualenv wrapper" which gives you some further
>> commands to make working with virtualenvs easier.)
>>
>> Regards
>>
>> Walter
>>
>
> I realize I could have used a shell script but since I was working with
> Python I thought I might learn some more Python by trying to use it.  As
> it turns out, I did learn quite a bit through this discussion.
>
> Thanks for the pointer to virtualenv wrapper.
>
> Regards,  Jim
>

I've worked on this a little more. If I create a file like:

#!/usr/bin/python
import os, subprocess
subprocess.Popen(args=["gnome-terminal",
     "--working-directory=/home/jfb/Documents/Prog/Python/breezygui"])

and execute it, it will take me to the correct directory.  Once there if 
I type in 'source bin/activate' I will get a virtualenv. However I can't 
figure out how to do it from my script.

I have tried adding "--command=source bin/active" to args=
but then I get this error:

There was an error creating the child process for this terminal
Failed to execute child process "source" (No such file or directory)

To check if I could even use "--command=", I added "--command=python" 
and I got a  python session.

Could some one tell me what I need to do to issue the command to setup 
virtualenv?

Thanks,  Jim




More information about the Tutor mailing list