Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Exe


  • Please log in to reply

#1
FutbolMolly

FutbolMolly

    Member

  • Member
  • PipPip
  • 33 posts
I created a py2exe. I have my hello.py script working, but now it does nothing. I need to add the the script so that it starts the server and launches the website. I would really appreciate any help, thanks!!

Molly
  • 0

Advertisements


#2
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
Ok, for my refrence.
You're trying to make a pyhton script that will start a server and open a website?
You want this to be an .exe?
Where is the server located? On the localhost?
Is this script going to run on this PC only?

Regards,
Olrik
  • 0

#3
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Artellos,

I already created the exe following the py2exe documentation. When I try to open it, the cmd just appears and goes away. I need for when someone clicks on the exe, the website to come up (my .py now is a webpage, just running on 127.0.0.1:8000). The script will run on other pc's but will not be public. It is going on a company's drive, that only people at the company can see. They won't let me create a website because of security. Hopefully I explained myself well, thanks for responding to me!!

Molly

Edited by FutbolMolly, 06 June 2008 - 07:59 PM.

  • 0

#4
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
I see, would you be able to share the sourcecode of the exe file?
simply use the following box.
[code][/code

They won't let me create a website because of security.

Im not sure what you mean with this :)


Just to get it right in my head. You have an .exe that will run your hello.py script but it only opens a cmd and closes?

Regards,
Olrik
  • 0

#5
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
I should be able to share the source code, they are just being weird about it going out on the internet. When you say just use that code, what would that do??

Well when I say they won't let me make a website because of security, i mean that my boss does not know very much about computers and is afraid that somehow someone will find out all of the information being put on the website if it is out on the public.. So i told him that i could just put it on the company's drive and then they would be the only ones able to see it.

So I created my hello.py script and everything looks good, so to make it possible for me to put it on the .py drive, I made it into a .exe. Now when I click it, that is when the CMD just appears. So I think for it to work I need to add some code in that will launch the server and show it as a webpage.

I could be wrong though, I am really new to programming so sorry if I am confusing!!

Thanks!!
Molly
  • 0

#6
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
I made a test.py and put this code in it:

import webbrowser
webbrowser.open('http://127.0.0.1:8000/admin')

When I run it in the cmd, it works and my site comes up.

I then added the same thing to my actual code, and when I run it in the cmd I get these errors:

C:\Documents and Settings\MOZIMMERMA\Desktop\mycode>setup.py
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: no commands supplied

C:\Documents and Settings\MOZIMMERMA\Desktop\mycode>models.py
Traceback (most recent call last):
  File "C:\Documents and Settings\MOZIMMERMA\Desktop\mycode\models.py", line 1,
in <module>
	from django.db import models
  File "C:\Python25\lib\site-packages\django\db\__init__.py", line 10, in <modul
e>
	if not settings.DATABASE_ENGINE:
  File "C:\Python25\lib\site-packages\django\conf\__init__.py", line 28, in __ge
tattr__
	self._import_settings()
  File "C:\Python25\lib\site-packages\django\conf\__init__.py", line 57, in _imp
ort_settings
	raise ImportError("Settings cannot be imported, because environment variable
 %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SE
TTINGS_MODULE is undefined.

Thanks :)
Molly
  • 0

#7
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
Does Models.py have any code in it?
Is the only thing you need to do open that web page?
How are you making it into an exe?
How will the client PCs run the exe file? Through a task or a manual click?
Wouldn't it be easier to set the "homepage" to "127.0.0.1:8000/admin" ?

Just a few more questions :)

Regards,
Olrik
  • 0

#8
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Yes, this is models.py's code:

from django.db import models

class Hazard(models.Model):
	name = models.CharField(max_length=100)

	def __unicode__(self):
		return self.name

	class Admin:
		pass

class HazardType(models.Model):
	name = models.CharField(max_length=100)

	def __unicode__(self):
		return self.name

	class Admin:
		pass

class HighwayType(models.Model):
	name = models.CharField(max_length=100)

	def __unicode__(self):
		return self.name

	class Admin:
		pass

class Probability(models.Model):
	number = models.FloatField()
	name = models.CharField(max_length=100)
	funny_name = models.CharField(max_length=100)
	
	class Admin:
		pass
	
	def __unicode__(self):
		return '%s\t|\t%s\t|\t%s' % (self.number, self.name, self.funny_name)
	
class Incident(models.Model):
	location = models.CharField(max_length=100)
	district = models.CharField(max_length=100)
	county = models.CharField(max_length=100)
	city = models.CharField(max_length=100)
	sr = models.CharField(max_length=100)
	seg = models.CharField(max_length=100)
	hazard = models.ForeignKey(Hazard)
	other_hazard_if_applicable = models.CharField(max_length=100)
	hazard_description = models.CharField(max_length=100)
	source_of_hazard = models.ForeignKey(SourceOfHazard)
	other_source = models.CharField(max_length=100)
	describe_conditions = models.CharField(max_length=100)
	highway_type = models.ForeignKey(HighwayType)
	adt = models.CharField(max_length=100)
	posted_speed_limit = models.CharField(max_length=100)
	site_distance = models.ForeignKey(SiteDistance)
	site_conditions = models.CharField(max_length=100)
	location_of_hazard_or_problem_relative_to_roadway = models.ForeignKey(LocationOfHazardOrProblemRelativeToRoadway)
	site_description = models.CharField(max_length=100)
	site_restrictions = models.CharField(max_length=100)
	photo_documentation = models.ForeignKey(PhotoDocumentation)
	geologic_setting = models.CharField(max_length=100)
	subsurface_conditions = models.CharField(max_length=100)
	surface_conditions = models.CharField(max_length=100)
	probability = models.ForeignKey(Probability)
	
	class Admin:
		list_display = ('location', 'district', 'hazard')
		list_filter = ('location', 'hazard', 'natural_vs_manmade')
		search_fields = ('hazard_description', 'district')

Yes, the only thing I need to do is for when people click on the file, for it to open up the webpage running at http://127.0.0.1:8000

I am making it into an exe by following this website:

http://www.pharscape...=...3&Itemid=51

The users will open it through a manual click

I am pretty sure that the homepage is already http://127.0.0.1:8000

I think that I am very close..

this is my setup.py

from distutils.core import setup
import py2exe

setup(console = ["models.py"])

import webbrowser
webbrowser.open('http://127.0.0.1:8000/admin')

When i remove the setup(console = ["models.py"]), the website will run if i have the server running.
I think that I have to have that though, don't I??
How will the user's open it if the server is not running, because I manually go in and say run server.

Thanks Artellos :)
  • 0

#9
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
Just 1 more question before I can give you some example code.
what does models.py do right now, What is it supposed to do?

You're close with py2exe, though you didn't completely get it.
I'll explain in the next post.

Regards,
Olrik
  • 0

#10
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Models.py is the code from the site. The site is supposed to be a place for Engineers to enter data about hazards that are happening on the road. Hope that makes sense..

Molly
  • 0

Advertisements


#11
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
It does, sort of :)
Remember you might need to change 127.0.0.1:8000 to the appropriate IP address in the company.
Alright, lets start working on it then.
On the C:\ make a new folder called "pyweb" and make a new empty python file.
In the python file put the following code.
import webbrowser
webbrowser.open('http://127.0.0.1:8000/admin')
Save it under the name "pyweb.py"

Now the next step is to make in installer python file.
Make another file and call it "setup.py"
Put the following code in
from distutils.core import setup
import py2exe


setup(
	windows = [
		{
			"script": "pyweb.py",
		}
	],
)

Now what we're going to do it make a simple batch file (Batch is basically a programming language built into windows that uses windows commands) that will compile the program "pyweb.py".
Make a new file and call it "compile.bat" and put the following code in there.

python concealipsetup.py py2exe
if errorlevel 1 pause

You have to make sure that you installed python properly and that python can be found in the systempath.
If you're not sure you can check simply by opening a Command Prompt and typing "python". If it brings up something looking like the code box below then you have it installed.

C:\Documents and Settings\Olrik>python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

If python is not set into the system variables then follow the steps below:
  • Right click "My Computer" and open the Properties.
  • Go to "Advanced" and at the bottom click the button "Variables" (or something similar).
  • Then in the bottom box find "path" and hit "Edit"
  • Then hit the right arrow key to go to the last part of the line and type ";<pythondir>" where <pythondir> is the directory Python is found. For me that is "C:\python25"

NOTE: If you want the initial Command Prompt of the program to be hidden, rename the program to "pyweb.pyw" and in the setup.py edit the name to "pyweb.pyw". Setup.py should be left alone and so should the compile.bat

Regards,
Olrik
  • 0

#12
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Okay, that worked :)

Now i think I need to add to my code, somehow for the server to start automatically, because it opens the browser but will not open since the server is not running.

Thanks so much!
Molly
  • 0

#13
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
You're welcome :)

Regards,
Olrik
  • 0

#14
FutbolMolly

FutbolMolly

    Member

  • Topic Starter
  • Member
  • PipPip
  • 33 posts
Do you know how what code I need to add for the server to automatically start?? If you don't want to help, that okay because you already helped me out a lot and I am thankful for that!!
  • 0

#15
Artellos

Artellos

    Tech Secretary

  • Global Moderator
  • 3,915 posts
It really depends, Is it a server with the site on it only?
How do the engineers usually access it?

How do you start the server?

Regards,
Olrik
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP