Using Pygame without installing - python

I'm making a real simple RPG game at college and I would like to use pygame. However, my college has a group policy disabling any Windows executables from running so I can't install pygame. Is there any way I can just import pygame by just having it in the same folder?

One thing I do with external python libraries is to download the source, build it and copy the built library into ${PROJECT_HOME}/lib/${EXTERNAL_LIB_NAME}. This way, I can run my python scripts with just standard python installation on a machine. To be able to use the external lib, you'll have to include the lib directory to sys path like this:
import os
from sys import path as syspath
syspath.append(os.path.join(os.path.dirname(__file__), 'lib'))
P.S.: Since pygame has C/C++ files to be compiled, you'd have to use mingw instead. Refer to this answer for that: error: Unable to find vcvarsall.bat
EDIT: In case you're wondering how to build pygame from source, you'll need to run setup.py build. This will build the python library into 'build' folder of the package directory and there you'd see how it should be placed in Python's directory. You will face the compilation problem in Windows as I've mentioned before, but you can easily fix that.
EDIT 2: Download link to contents of 'lib' for PyGame:
Python 2.7: http://dl.dropbox.com/u/71422266/pygame27.7z
Python 3.2: http://dl.dropbox.com/u/71422266/pygame32.7z

If you're allowed to run stuff from a USB drive, one option would be to use Portable Python 2.7.3.2, which includes PyGame 1.9.1.

Related

Not able to import Tkinter in Maya 2014

I am using windows 7 and Autodesk Maya 2014.When i am trying to import Tkinter i am getting error.please tell me how to solve error given below ?
How to install any python package in Auto desk Maya 2014 ?
import Tkinter
Error
Error: line 1: ImportError: file C:\Program Files\Autodesk\Maya2014\Python\lib\lib-tk\FixTk.py line 65: DLL load failed: %1 is not a valid Win32 application
I added a few Python modules to Maya with the "addsitedir-trick" explained at the end but not every python module will be playing nicely with Maya.
Python on Windows is built with Visual Studio 2008 Professional. Maya uses it's own Python interpreter but Autodesk builts Maya with another Visual Studio version. This can lead to problems if you insall python modules and try to use them with Maya. Beatuifully explained here (together with a the hard solution of compiling the wanted modules yourself):
http://p-nand-q.com/python/building-python-27-with-vs2010.html
What you can try: Install Python 2.7 on your Windows-box, install the module you want to access in Maya (eg with pip). Now in Maya add your system SitePackages (where you just installed the module to) to your Maya-Python-Interpreter SitePackages like so:
import site
site.addsitedir("/path/to/your/python27/Lib/site-packages")
Even cleaner solution would be to use a virtualenv instead of the global site-packages folder! (That's at least what i have done to get psycopg2 and requests play with Maya)
But as mentioned in the beginning of this answer there is a possibility that this may fail (with strange errors).
By the way: I highly recommend to use pyside instead of Tkinter if you want to do GUI stuff in Maya. Or the Maya-Wrappers preferably via pymel. (http://help.autodesk.com/cloudhelp/2017/ENU/Maya-Tech-Docs/PyMel/ui.html)

Py2Exe "Missing Modules"

I'm trying to convert my python project into an exe using Py2Exe. It is worth noting that cx_freeze complains about the same three "missing modules", along with several dozen others. The problem is, no one anywhere tells how to resolve this.
I'm building on MS Windows XP 32-bit (VirtualBox).
C:\Documents and Settings\Jason\Desktop\redstring2>python setup.py py2exe
running py2exe
running build_py
creating build
creating build\lib
copying redstring.py -> build\lib
3 missing Modules
------------------
? readline imported from cmd, code, pdb
? win32api imported from platform
? win32con imported from platform
Building shared code archive 'dist\library.zip'.
Copy c:\windows\system32\python34.dll to dist
Copy C:\Python34\DLLs\select.pyd to dist\select.pyd
Copy C:\Python34\DLLs\_ssl.pyd to dist\_ssl.pyd
Copy C:\Python34\DLLs\_ctypes.pyd to dist\_ctypes.pyd
Copy C:\Python34\DLLs\_lzma.pyd to dist\_lzma.pyd
Copy C:\Python34\DLLs\_hashlib.pyd to dist\_hashlib.pyd
Copy C:\Python34\DLLs\pyexpat.pyd to dist\pyexpat.pyd
Copy C:\Python34\DLLs\_socket.pyd to dist\_socket.pyd
Copy C:\Python34\DLLs\_bz2.pyd to dist\_bz2.pyd
Copy C:\Python34\DLLs\unicodedata.pyd to dist\unicodedata.pyd
My setup.py is as follows.
#!/usr/bin/python python
from setuptools import setup
import py2exe
setup(name="Redstring",
version="2.0",
description="REDundant STRING generator",
author="MousePaw Labs",
url="http://www.mousepawgames.com/",
author_email="info#mousepawgames.com",
data_files=[("", ["redstring.png", "redstring_interface.glade"])],
py_modules=["redstring"],
)
This is a Python 3.4 project using GTK+ 3 (built in Glade). It runs just peachy on Ubuntu, and from python redstring.py, but I can't get the thing to compile down to an .exe.
So far I tried import platform, from platform import win32api, and all the like in both redstring.py and setup.py, along with importing platform via py2exe options in the setup file.
win32api and win32con are part of Mark Hammond's Python Windows extensions (aka pywin32). readline is a module that is used (if present) by some code interacting with the console.
Both readline and pywin32 are optional modules/packages that are not abolutely required but will be used when present.
All in all - py2exe notices that these modules/packages are referenced by some code which will be included into your exe (it even mentions the modules that reference these mod/packages: cmd, code, pdb, platform).
I hope you have tested your script - in the 'non-compiled' form, if it works correctly than you can safely ignore these messages: they are only warnings.
The reason that no executable is built is that the line 'console=["redstring"]' or 'windows=["redstring"]' is missing in the setup() call.
So, it would happen that these libraries were never installed to begin with. Python may be "batteries included", but not to this extent. However, I'm answering this because fixing it isn't the most obvious thing in the world to some (myself included).
You need to install win32api (or pywin32, as it is officially called) from Sourceforge (at the moment, browse the files for the latest version, as the Download button links to README.txt) That will resolve win32con as well. (You cannot install pywin32 from pip at the moment, unfortunately.)
readline is not compatible with Windows, yet it asks for it. You actually have to install pyreadline, which is easiest from pip install pyreadline.
That should resolve all of those issues for py2exe. I'm still having trouble, but it's different trouble, so it's a different question.

Python & Tide SDK - import external module?

Since python is bundled with the Tide SDK, I can't figure out how to use access external modules. I've tried copying the module folder "Lib/site-packages/YourModuleHere" to the tide SDK directory, and this suggestion here: TIdeSDK Python module import but with no success. The module I'm trying to use is https://github.com/burnash/gspread
Any ideas?
Thanks...
You may try http://www.py2exe.org/index.cgi/Tutorial
to convert your python code to exe with all needed modules then use Ti.Process.createProcess() to call your exe
In current version of TideSDK, loading custom python modules is not supported.It loads default set of Python modules compiled within the SDK.
I've had some luck installing a view external modules by running setup.py install from TideSDK's python.exe
This post helped:
Installing python modules in TideSDK
For Windows 7:
launch powershell
cd into the module folder
run:
C:\ProgramData\TideSDK\Modules\python\1.3.1-beta\python.exe setup.py install
It installs the module in \Lib\site-packages, as it should, and I'm able to use the import function in the python code.
This has worked for PIL and I'm trying to get it to function with pywin32. I'd love to hear if it works for other modules

How to use the win32gui module with Python?

Im my Python file, I have imported the win32gui module like this:
import win32gui
I have also downloaded win32gui but don't know how to make my script run. How can I run my Python script which imports win32gui? When I run it, I get:
ImportError: No module named win32gui
Sorry for the newbie question but I'm trying to learn Python so don't know much about it.
When on a windows platform, I usually go for the executables. They should work all the time. Try perhaps one of the files listed here:
http://sourceforge.net/projects/pywin32/files/pywin32/Build216/
It's the most recent build. Choose the one appropriate to your Python's version.
this is a module from Marc Hammond's well-known pywin32 extension module, you can also get the source and compile it quite easily (I found I needed to do this because I needed a 64 bit build and couldn't find one at the time). The mercurial address to get it is:
http://pywin32.hg.sourceforge.net:8000/hgroot/pywin32/pywin32
there are visual studio project files in the .\pywin32\win32 directory...

Can Python 2.5 and 2.7 coexist along with wxPython, py2exe and comtypes (try to resolve MSVCP90.dll problem)?

I was writing a code which uses wxPython and comtypes. I have python 2.7 installed on my machine (Windows) along with wxPython, comtypes and py2exe. while trying to build it I got the following error:
error: MSVCP90.dll: No such file or directory
So, I did research I came to know about two solutions:
1. Copy Microsoft.VC90.CRT.manifest and msvcp90.dll to your machine and prepare your setup like as follows:
from distutils.core import setup
import py2exe
from glob import glob
data_files=[("Microsoft.VC90.CRT", glob(r'c:\shared_dlls*.*'))]
setup(data_files=data_files, console=['main.pyw'])
2. Use Python 2.5 along with wxPython, comtypes and py2exe
Now, I have following questions:
In first case:
a. Do I need to have Visual Studio license in order to use these files? or that can be used without any worries.
b. What if I compile it using aforementioned method? Does it still require MSVC90.dll on the user machine to execute? I think - No. Please correct me if I'm wrong. I want to remove any dependency and give user an exe which the user can directly execute without any dependency.
In Second case:
As I have Python_2.7 installed on my machine along with aforementioned modules. I would like to know can I install Python 2.5 on the same machine? Can they co-exist? If yes, do I need to install another copy of wxPython, comtypes and py2exe for this.
Please suggest me what is the best solution. How should I proceed? It's kind of blocking me.
Thanks in advance!
Python 2.5 and 2.7 (and all other versions of Python) co-exist very well. You may need to change your path to use the correct version of Python.
You will need to install the Python 2.5 builds of wxPython and py2exe. You will also need to install comtypes for Python 2.5. That installer will detect your Python installations by checking the registry.
I simply downloaded MSVCP90.dll file from here: http://www.dllme.com/dll/files/msvcp90_dll.html
and then pasted it into Python27\DLLs. It worked after that.
Did you try to install Visual C++ redistribuables?
I think you don't need a VS license for this.

Categories

Resources