first of all, sorry for this dumb question.
secondly, this is the scenario, i made executable file from python, my app need to connect to mysql database, in my app script is using mysql.connector.
thirdly, what i want to know, is my app can run and connect to mysql database in another pc that does not have mysql driver installed? *because of poor resource, right now i can't just try and find out my self.
if it can't, can i using sqlite and then all the pc client data saved in 1 file database that place in shared folder, so 'admin' can read it anytime?
thank you so much
Related
I have made a PostgreSQL database, and I am trying to connect a python script to it. I need to enter the server name to the script. I have the database name, but I don't know what the server name is. Where do I find that? If it helps I am working through Heroku Postgres.
The official article in the DevCenter states:
To use PostgreSQL as your database in Python applications you will need to use the psycopg2 [...] to connect to DATABASE_URL in your code.
So I guess there is no server name needed with that package.
I've made a python application the relies on a mysql database. Is there anyway I could somehow save the mysql database into a file format along with the code to be distributed to my teacher? He needs to be able to view the code and run it, so I am not able to export it to a .exe file. I'm currently using MYSQL workbench to run my database on mac. Where as my teacher uses a PC and uses Microsoft access
Basically, I want it where I have a folder that container my program saved as a .py file, and the mysql file in the same folder, and my teacher will simply open my code and run it, and the program fully works and runs with the database fully integrated.
I think you have 2 options.
Option A would be to export a so called MySQL dump, send it with the files and use Python to import it into the MySQL database. This option requires that your teacher has MySQL installed.
Option B would be to not use a database application and work with a CSV file instead. With this option you can just send the CSV file with your code. This option obviously requires to change your Python code so it uses the CSV file instead of the database.
From my point of view (I may miss something) you should not have a database installer in your files which installs a DB on your teachers‘ computer
I've followed the Djangogirls tutorial and usually the tutorial calls for you to create a database on pythonanywhere. This usually works without a hitch when using sqlite3 however this time I'm using postgresql and I got the below error when I ran the migrate command in the console:
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql
What does this mean exactly?
using python 3.5.1
django 1.9.8
postgresql 9.4
Thanks
Ok after reading around some more, this is my problem in a nutshell.
I have postgresql running locally. I then deployed the wbapp onto pythonanywhere. Whilst there I tried to create the database by running migrate which resulted in the above error.
Since then i realised that I had to setup postgresql to run on pythonanywhere. I followed the instructions and did that, but what I don't understand is do I now have to create the database from scratch? And if that is the case what happens to all my tables etc. from my local database?
To clarify, you should not be trying to connect to your local postgres. Instead, you should setup postgres on pythonanywhere, and make sure that your django settings.py is pointing the database address and port to the pythonanywhere database. Which is not local to the console/webapp server that you are running your code on. Instead, go to the pythonanywhere database tab and look at the address/port that is given to you.
According to their help page you need to upgrade to a paid account to be able to use postgres.
I looked at the sqlite.org docs, but I am new to this, so bear with me. (I have a tiny bit of experience with MySQL, and I think using it would be an overkill for what I am trying to do with my application.)
From what I understand I can initially create an SQLite db file locally on my MAC and add entrees to it using a Firefox extension. I could then store any number of tables and images (as binary). Once my site that uses this db is live, I could upload the db file to any web hosting service to any directory. In my site I could have a form that collects data and sends a request to write that data to the db file. Then, I could have an iOS app that connects to the db and reads the data. Did I get this right?
Would I be able to run a Python script that writes to SQLite? What questions should I ask a potential hosting service? (I want to leave MediaTemple, so I am looking around...)
I don't want to be limited to a Windows server, I am assuming SQLite would run on Unix? Or, does it depend on a hosting service? Thanks!
I could upload the db file to any web hosting service to any directory
Supposing that the service has the libraries installed to handle sqlite, and that sqlite is installed.
Would I be able to run a Python script that writes to SQLite
Yes, well, maybe. As of Python 2.5, Python includes sqlite support as part of it's standard library.
What questions should I ask a potential hosting service
Usually, in their technical specs they will list what databases/libraries/languages are supported. I have successfully ran Python sites w/ sqlite databases on Dreamhost.
SQLite would run on Unix
Most *nix flavors have pre-packaged sqlite installation binaries. The hosting provider should be able to tell you this as well.
I have a written a very small web-based survey using cgi with python(This is my first web app. ).The questions are extracted from a MySQL database table and the results are supposed to be saved in the same database. I have created the database along with its table locally. My app works fine on my local computer(localhost). To create db,table and other transaction with the MySQL i had to do import MySQLdb in my code.
Now I want to upload everything on my personal hosting. As far as I know my hosting supports Python,CGI and has MySQL database. And I know that I have to change some parameters in the connection string in my code, so I can connect to the database, but I have two problems:
I remember that I installed MySQLdb as an extra to my Python, and in my code i am using it, how would I know that my hosting's python interpretor has this installed, or do I even need it, do I have to use another library?
How do I upload my database onto my hosting?
Thanks
If you have shell access, you can fire up the python interpreter by running python and type import MySQLdb at the >>> prompt. If you get no errors in return, then its installed.
Likewise, if you have shell access, this page will help you with importing and exporting using the mysql command. I found it by googleing "import export mysql".
You can write a simple script like
import MySQLdb and catch any errors
to see if the required package is
installed. If this fails you can ask
the hosting provider to install your
package, typically via a ticket
The hosting providers typically also provide URL's to connect to the MySQL tables they provision for you, and some tools like phpmyadmin to load database dumps into the hosted MySQL instance
To check if MySQLdb library is installed on your hosting, simply open a python shell and type: import MySQLdb. If everthing goes ok, you're readt to go. If you get: ImportError: No module named MySQLdb, that means the the library is not installed and you nedd to install it.
You need that library or some library that provides similar support, because Python does not support native access to MySQL databases.
To transfer you database to your hosting check mysqldump.