Results 1 to 6 of 6

Thread: Python script starts only from console

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    Python script starts only from console

    Hello,
    I got into Python for some time and is a delight. I stumbled upon a small problem while beast. I created a very simple little game that works on hair, but the graphics were entirely within my script using commands create_line, create_rectangle, create_oval, etc. not knowing at the time how to work with pictures under Python. Now I duplicated the file of my game, and have replaced all my graphic part with calls to external images. Jpg and. Png. But since my script does not want to engage with the mouse, but only from the console. I have checked the file properties it was executable, but nothing works. Other scripts themselves, to throw out since my file browser. If someone has an idea? Thank you in advance.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Python script starts only from console

    Hello,
    When you say run the script with the mouse, it's action that leads you to the window on which you have the choice between Show, Lancer, etc. ...? For my part, I always launch my scripts on the command line. I think I have not understood your exact problem, so if you explain more clearly then it would be more helpful to us.

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Python script starts only from console

    Hi
    No, when I speak to run the script with the mouse, I spoke to execute my script by double-clicking its icon in the file manager, like to open a document for example. My script starts up via the terminal but not otherwise. The other scripts I created to launch them all too well "in graphic" only through the terminal.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Python script starts only from console

    Hello,
    If your program does not start per-click (or double-click depending on the settings), it is because he does not start in the correct folder (the one where your script) at once, it can not find your pictures and plant. In launching the console, you do not have this problem because the console is on file in your script. Your other scripts which they operate, must not use external files. The solution I use, at the beginning of each of my python programs I put these lines.
    import os, os.path, sys
    HERE = os.path.dirname (sys.argv [0])
    APPDIR = os.path.abspath (HERE)
    sys.path.insert (0, APPDIR)
    os.chdir (APPDIR)
    This changes the current folder in the program, and I can use the files without error.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Python script starts only from console

    Hello,
    Just go through these part of code
    Code:
    import os, os.path, sys
    import of python modules needed
    Code:
    HERE = os.path.dirname (sys.argv [0])
    recovery path python file (the one that starts) in the variable HERE
    Code:
    APPDIR = os.path.abspath (HERE)
    Variable APPDIR well be the full path HERE
    I'm not sure we need to go through rather than APPDIR HERE but good.

  6. #6
    Join Date
    May 2008
    Posts
    2,389

    Re: Python script starts only from console

    Hello
    In addition for the above code, you can add this
    Code:
    sys.path.insert (0, APPDIR)
    APPDIR is placed in the path. If there are personal to import modules, it can be useful.
    Code:
    os.chdir (APPDIR)
    Here is what allows the script to run properly.
    It changes the path system to be APPDIR.

Similar Threads

  1. Ubuntu crashes after deleting a python script...
    By akhar in forum Operating Systems
    Replies: 1
    Last Post: 02-01-2010, 09:55 AM
  2. ComboFix Script and Recovery Console
    By Zipp in forum Windows Software
    Replies: 4
    Last Post: 07-11-2009, 02:27 PM
  3. How to call perl script from Python?
    By Jhonwho in forum Software Development
    Replies: 3
    Last Post: 23-07-2009, 09:59 PM
  4. Download Python 3.0 / Python 3000
    By Amaresh in forum Software Development
    Replies: 6
    Last Post: 24-02-2009, 09:28 AM
  5. Python starts slowly
    By Bigga Lexx in forum Software Development
    Replies: 2
    Last Post: 10-01-2009, 06:18 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,351,595.54425 seconds with 16 queries