How to access a MS SQL Server using Python 3? - python

I'm using a linux machine to make a little python program that needs to input its result in a SQL Server 2000 DB.
I'm new to python so I'm struggling quite a bit to find what's the best solution to connect to the DB using python 3, since most of the libs I looked only work in python 2.
As an added bonus question, the finished version of this will be compiled to a windows program using py2exe. Is there anything I should be aware of, any changes to make?
Thanks

One option would be trying the pyodbc branch for python 3 support. I think some people have reported success, but you might want to inquire at the pyodbc discussion group.
If you stick to platform independent parts of the python library (most of it), you shouldn't have any issues on windows with py2exe.

I can't answer your question directly, but given that many popular Python packages and frameworks are not yet fully supported on Python 3, you might consider just using Python 2.x. Unless there are features you absolutely cannot live without in Python 3, of course.
And it isn't clear from your post if you plan to deploy to Windows only, or Windows and Linux. If it's only Windows, then you should probably just develop on Windows to start with: the native MSSQL drivers are included in most recent versions so you don't have anything extra to install, and it gives you more options, such as adodbapi.

If you want to have portable mssql server library, you can try the module from www.pytds.com. It works with 2.5+ AND 3.1, have a good stored procedure support. It's api is more "functional", and has some good features you won't find anywhere else.

Related

How do to use a python script in Unity?

I'm trying to run a face detection model in Unity. It gets input from the webcam, then spits out a face. But trying to make this work with C# has been an absolute nightmare. And despite all my suffering, I still haven't been able to make it work!
If I could use python, I'd be able to get it done easily. So, obviously, I want to find a way to get a python script working in Unity. But IronPython is the only thing I've been able to find, and it's outdated.
I need either knowledge of how to make IronPython work in spite of being outdated, or some other method. Please.
Unfortunately, Unity at this time does not support Python. Although, there is an asset that you can use a bit of Python with. I am not sure what you can do with this asset but I know it could help a minimal amount:https://assetstore.unity.com/packages/tools/integration/python-interpreter-645
Quick Note: Most programming languages work about the same way. If you figure out the documentation and grammar/punctuation for C#/UnityC#, you should be off just fine.
I try to use python once on Unity and I found a few ways:
There is a package call "IronPython" where you can add a python file to your unity project and then call a function from C# to your python code, to do that you should follow this:
We already know that we can use python to use .net internal calls.
Now we may use the same to start a console that can accept a scripting language in Unity engine.
To do this we have to include certain dll files.
These dll files must be present in Assets>plugins
IronPython.dll
IronPython.Modules.dll
Microsoft.Scripting.Core.dll
Microsoft.Scripting.dll
Microsoft.Scripting.Debugging.dll
Microsoft.Scripting.ExtensionAttribute.dll
Microsoft.Dynamic.dll
Once the Plugins are in place.
Initiate the Cs code
PythonEngine engine = new PythonEngine();
engine.LoadAssembly(Assembly.GetAssembly(typeof(GameObject)));
engine.ExecuteFile("Test.py");
Where test.py is the python code.
Initiate python side:
import UnityEngine from UnityEngine
import *
Debug.Log("Hello world from IronPython!")
References:
https://github.com/cesardeazevedo/Unity3D-Python-Editor
http://techartsurvival.blogspot.in/2013/12/embedding-ironpython-in-unity-tech-art.html
IronPython in Unity3D
the issue with this way is that most of the python module are not supported.
2.the second way is to create a file like json that contain the data you want to send to the json and then create an output json that send the output from the python script, this way is very limited with what you can send because the data must be contain in your json.
the last way that work for me is to install the Nuget package and copy the script from python to c# line by line with the relevent module installed in Unity and it's work for me, but copy a long code can take time.
this is a reference to the package:
https://github.com/GlitchEnzo/NuGetForUnity
and then to install the relevent package you should press on NuGet → Manage NuGet Packages and the choose the relevent package(for me it was Numpy and it work grate).
hope it will help you
I don't know how recent it is but there is a Unity package for python available on unity 2019.3 and further versions.
Warning the first versions of this package can't use Python3.
You can see more for yourself by the following link.
https://docs.unity3d.com/Packages/com.unity.scripting.python#2.0/manual/index.html
I hope this may help you.
We are thrilled to announce that Python for Unity 4.0.0-exp.5 is now available!
4.0.0-exp.5 is a major upgrade from our last public release, and incorporates a large number of changes. In summary:
Based on Python 3.7; scripts based on Python 2.7 will need to be ported.
Users no longer need to install Python on their system.
In-process Python is no longer reinitialized when the Unity domain reloads.
Removed the out-of-process API. The PySide example now runs in-process and is much simpler.
Limited support for a virtual environment workflow via the ProjectSettings/requirements.txt file.
Many bug fixes.
Documentation for the Python for Unity package is available here, and the full changelog can be found here.
This is an experimental release, and thus is not visible in Package Manager. To install this package, open Package Manager, click the + at the top left and select Add package by name.... Enter com.unity.scripting.python as the name and and 4.0.0-exp.5 as the version and click Add. Alternatively, you may edit Packages/manifest.json and add "com.unity.scripting.python": "4.0.0-exp.5", to the list of dependencies, or edit the existing entry for Python for Unity to update the version.
Soursce: https://forum.unity.com/threads/python-for-unity-release-announcements.1084688/
Documentation: https://docs.unity3d.com/Packages/com.unity.scripting.python#4.0/manual/index.html
Unity not supported python, But you Can write Python Code and run it by Socket programing, Create Server with python and send data,in C# Connect to server and use data sended with python.

What versions of Python will work in Windows XP?

I would like the most advanced version of Python that still works on Windows XP. I need both Python 2 and Python 3.
What versions of Python will work on Windows XP?
I found that Python 2.7.9 and Python 3.4.4 are the newest versions of Python that work in Windows XP. I found this out through trial and error.
I've found a desperate guy (Daniel Pistelli) who didn't give up at the windows error dialog:
https://ntcore.com/?p=458
I like how he approaches the topic:
If we try to start any new application on XP, we’ll get an error
message informing us that it is not a valid Win32 application. This
happens because of some fields in the Optional Header of the Portable
Executable.
[...]
Fortunately, it’s enough to adjust the fields in the executable we want to start (python.exe), there’s no need to adjust the DLLs as well. If we try run the application now, we’ll get an error message due to a missing API in kernel32. So let’s turn our attention to the imports.
And then he goes on for another 5-6 screens. To sum it up, apparently you'll have to:
Modify the python.exe header,
Run a tiny Python script to remap some DLL calls,
Recalculate some binary hashes,
Create a fake kernel32.dll with certain calls forwarded,
Modify python37.dll to point to this fake thing,
and then you're all set. To be honest I couldn't quite follow (let alone verify!) some of the steps but it looks legit and there are links with Daniel's half-baked solutions for the harder parts, also a lot of Python sources explained. I will definitely give this thing a try.
In fact, here are the final scripts from his GitHub page:
https://github.com/dpistelli/xptmrt
Moral of the story: you can be crazy, but you'll never be dismantle-all-dlls-and-exes-and-open-hexeditors-and-disassemble-hashing-algorithms-and-mock-it-all-together-so-it-works-under-xp-crazy!
Someone had built Python 3.4.10, which is slightly newer than the officially prescribed Python3 v3.4.3/3.4.4 for Windows XP. Since it comes from the third-party (not the official Python website), use at your own risk,
-->Download<--
i tried 3.3.3 but i came up with an error message use 3.4.3/2.7.9 they are the only versions that work now sadly
There are several custom builds of Python >3.44 suitable for Windows XP. A poster at reddit has provided Python 3.55 here:
https://www.reddit.com/r/Python/comments/3tgi0t/python_35_x86_on_windows_xp/
Here is an XP compatible build of 3.6.15 source code only:
https://alex-free.github.io/winxp_python3.6.15/
At the MSFN forums someone has provided an XP compatible build of 3.8.1350 here:
https://msfn.org/board/topic/183741-python-3813-for-windows-xp-sp3/
Official website says about 3.4.10: https://www.python.org/downloads/release/python-3410/
Any of them, python is very platform independent. Some features might not work, but that would best be found in the documentation.

Using Python in NetBeans 8.1

I'm trying to add Python functionality to NetBeans 8.1. I downloaded Python from the Python website here. (I'm using Windows 10, by the way.) I also downloaded the NetBeans plugins "Python" and "Jython Distribution" (required by the former). Now I have two questions:
1.
When I create a new Python project, I have these options:
Based on the description for the "Setuptools" choice, I'm guessing that I shouldn't use that one since it's not for Windows. So am I correct in choosing "Python Project - Ant"?
2.
The Python platform that is selected by default is "Jython 2.7.0," as shown below.
I'm assuming that what I got from the Python website was a Python platform too, so I'd like to use that if possible. But in trying to add another platform, I don't know what file to choose in my Python folder. All of the ones I've tried result in the error:
I guess I could use the Jython platform, but I would think that the stuff I downloaded straight from Python would be the best. Do I need to add and make default the stuff I downloaded? Or should I ignore that and just use the Jython platform?
If yes to "should I add a platform", what file do I select?
Thanks in advance for any help.
EDIT:
I was able to create and run successfully a Python project using the "Python Project - Ant" option as mentioned in question 1, using the Jython platform. So question 1 is taken care of. I still would like to be able to use the Python platform I downloaded from their website, though, so question 2 still needs an answer.
For those who are trying to run other python distributions from netbeans, here is what i found:
From python wiki - https://wiki.python.org/moin/IntegratedDevelopmentEnvironments
Python/Jython support in NetBeans -- Open source, allows Python and Jython Editing, code-completion, debugger, refactoring, templates, syntax analysis, etc.;
UPDATE: Netbeans 7.0 released without Python support. Check
http://wiki.netbeans.org/Python70Roadmap for upcoming Python support.
So it looks like, python (Cbased) will no longer be suported in NetBeans, only Java-based Jython - also look on this question:
What is the difference between Python vs Jython vs IronPython vs wxPython?

Using .NET from within Python on win32? Is python.net viable?

I'm trying to write a quick and dirty little program to poll a WASP-B ANT+ to wifi gateway on windows, using python (the language I'm most familiar with). The WASP-B device has an unpublished UDP protocol that is mixed up with NDA's and so forth, but they have a published .NET library for win32 programming. So ... I googled around a bit and found IronPython and python.NET. If I understand correctly, IronPython is a .NET application or something? Not really what I'm after, I just want to be able to use the "stuff" in the WASP-B's .NET library from within a python program, so I think python.NET is the better option for me.
As far as I can tell, python.NET isn't all that active though - does anyone here know if it's live, if it'll work with current (3.x) python on Windows and if I'm on the right track?
On sourceforge, python.NET hasn't been touched since Jan 2013 :
http://sourceforge.net/projects/pythonnet/
The WASP, for anyone interested :
http://www.npe-inc.com/products/products-wasp.html
If you're looking for a Python variant that plays very well with .NET, then I highly suggest Iron Python: http://ironpython.net/ it is an open-source variant of Python that was integrated with the .NET framework, allowing it to behave similarly to one of the .NET-friendly languages.
As far as being active, the last update was made on May 25, 2014, which is pretty recent. The updates are not frequent, but for the most part there is no need for them, beyond some improvements and fixes. I would suggest giving it a try and see if it works for you. It's hard to answer a question of something being the right thing for the job unless youn give it a try.
IronPython works wells within .NET environments (calling .NET assemblies). If you stay within .NET framework then IronPython is recommended. Note Python 3 port is in progress and the syntax is not supported yet (Jan 2015).
But CPython (main Python implementation) works well with Python.NET both for extending and embedding. The reason for using CPython with Python.NET is if you need libraries that call Python C-API (not supported by IronPython), like Numpy, Scipy, Pandas, Cython, Matplotlib, etc. Python 3 port is here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
https://github.com/renshawbay/pythonnet/

What version of Python should I be using to develop web applications?

Currently I have Python 3.1.1 installed on my system, same version on my server with WSGI 3.0 running on Apache 2.2.
I want to keep using Python 3.1, but I'm finding that lots of libraries/frameworks don't support it yet, namely Django, Pylons, MySQLdb, etc.
I also checked an account I have on a friend's server, and it is running Python 2.3.4...
I want to write a sort of blog/forum type application that I can expand into a CMS, and eventually write related desktop applications for, as sort of a long-term pet project.
I'd like to use the newest version of Python possible for best security and highest consistency with the desktop-applications-to-be, while still maintaining a good level of portability, and supporting most of the frameworks and libraries I will use.
But I'm lost on which one I should pick. It seems like 2.4 would have the greatest amount of portability but it's sort of old, and I don't want to wind up using a bunch of post-2.4 features that won't compile, and having to re-write with messier code to compensate for it. 2.6 would be better, but it seems like lots of libraries are still porting over to that, and 3.1 would be the best since it eliminates a lot of cruft from the language.
One thing I'd like to highlight is that it'd be nice to know what I will be missing if I choose an older version of Python. For example, if I were to need my application to run on my old Python 2.3.4 account on my friend's server, what libraries/features would I be lacking that exist in newer versions? What problems would I surely run into that would make me wish I was using Python 2.6 or 3.1? Which of these features would be available via __future__ imports?
So, what would be the best direction to go? Should I just use 2.6 and deal with any issues? Should I go for 2.4 to maximize my ability to possibly distribute it to shared hosting environments? Or should I just jump into 3.1 and have a slightly-crippled application until libraries like MySQLdb catch up?
For now, Python 3 is not widely deployed in production. Depends on what you use Python for. If it's just for one off scripts, it will be ok either way, if the idea is to use third party modules, C modules and or deploy painlessly, then settle for any of the 2.4+ versions. Many projects strive to keep 2.3 compativility, but you shouldn't have any problems to use 2.4-2.6, as the changes in the language are minor. If you can, use 2.6, as it's the closest to Python 3, as it has some features backported to it.
The problem with Python 3 is a Catch 22:
most useful third party modules are still not ported to 3, as developers are waiting for wide usage,
people can't migrate because modules they rely on haven't migrated yet, keeping the sage low.
You should not have any problems using any of the 2.4-2.6, give 3, some time.
Use Python 2.6
Begin with Python 2.5 if you're not sure.
Have a look at Google App Engine (based on Django). It's using Python 2.5 and it's free.
However, you will not be able to call scipy (for example) or any libraries with "C" inside.
You will have the greatest amount of portability with Python2.5. Moreover, python3k is not really used in the industry.
"2.6 would be better, but it seems like lots of libraries are still porting over to that"
What? What libraries -- that you need -- are "still porting over to that"?
"3.1 would be the best" "but I'm finding that lots of libraries/frameworks don't support"
Correct. You've stated that twice in the question. That's very clear.
"Should I just use 2.6 and deal with any issues"
What issues? Do you have any specific concerns?
It seems to work really, really well. What are your specific concerns?
For intranet web apps I had to install python 2.5 (due to combination of wiki, bug tracker, and httpd WSGI compatibility).
For custom web apps I standardized on python 3.2.
Thus I have both installed simultaneously. I write for 3.2 and bring specific libraries up to spec as needed. However large packages which I don't want to modify use their own 2.5.
Compatibility between 3.2 and 3rd party packages is still an issue at this time, and so is the lack of proper python recipes.
In summary: Install two versions.

Categories