problem with pyodbc import

This is the place for queries that don't fit in any of the other categories.

problem with pyodbc import

Postby dogdaynoon » Mon Jun 24, 2013 3:23 pm

Hello.
I have installed python 3.3 running fine.
I am using a windows 7 64bit version and i have ran the installer for pyodbc module for sql connections.
my problem is very interesting:
if i create a file in D:\pythonWorkingDir\project_n and call it for example: test.py
and in this file include the following code only:
Code: Select all
import pyodbc as p


when i go to the command line and traverse to D:\pythonWorkingDir\project_n and run this command: test.py
i get an error for module not found "pyodbc"

Now if while in the same directory I instead run this command:
Code: Select all
D:\pythonWorkingDir\project_n>python
>>> import pyodbc as p
>>>

i receive no errors and can use the module

Why is python seeing the module from the shell but not from a file execution?
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm

Re: problem with pyodbc import

Postby micseydel » Tue Jun 25, 2013 1:19 am

It looks like you have two versions of Python installed, and the one that runs when you just specify the Python file is different from the one you get by explicitly invoking Python. I suspect if you use "python test.py" it would work where just "test.py" gives you an error.

Also, as a tip, I would recommend against "test.py" as a filename since if you use anything that uses the built-in test module, it'll break.
Join the #python-forum IRC channel on irc.freenode.net!

Please do not PM members regarding questions which are meant to be discussed publicly. The point of the forum is so that others can benefit from it. We don't want to help you over PMs or emails.
User avatar
micseydel
 
Posts: 1220
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: problem with pyodbc import

Postby dogdaynoon » Tue Jun 25, 2013 5:38 pm

Nope only one version.
but to be sure, i uninstalled pyodbc 64 bit and python 3.3.1 64bit
installed python 3.3 32 bit and pyodbc 32 bit
and i am having the same problem.
however now if i copy the pyodbc files into the working directory it will work but i receive errors that the python33.dll is not compatible with python.
well.. whatever. so far it works if i call C:> python filename.py
so i will just use that method for now.
i am kind of tired of learning programming languages only to find out that i have to learn how to custom install them on different computers. :roll:
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm

Re: problem with pyodbc import

Postby metulburr » Tue Jun 25, 2013 6:38 pm

i am kind of tired of learning programming languages only to find out that i have to learn how to custom install them on different computers.


of course you have to custom it for different computers, especially dealing with 3rd party modules such as your doing. If one of your computers ran windows 32 bit and another ran windows 64 bit, you would not use the same python install for both. The process is different based on which OS your on. There is also less headaches dealing with linux, opposed to windows. Either way though there should be a setup file to install those 3rd party modules. As long as you install the 3rd party module to a specified python version and invoke that python version, I dont see why there would be problems.

For future reference: It would also be better if you copied and pasted the *exact* message you get when you execute your script. AKA I executed this code and got this message. I have a 64 bit Windows 7, Installed python3.3 64 bit from this link sort of example

I also have a feeling it might be regarding your indicated D drive versus your C drive. Although i am not positive.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1383
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: problem with pyodbc import

Postby dogdaynoon » Wed Jun 26, 2013 6:50 pm

of course you have to custom it for different computers

I know, I know.. I just get tired of spending days trying to get this module or that compiler or that web server to work right... sigh...
I am running windows 7 pro 64 bit w/ sp1 on an hp elitebook 8770w
Okay, so I thought about the C: path problem as well and ended up uninstalling python and pyodbc.
I then installed 32 bit python 3.3.2 in C:\python33 and pyodbc-3.0.6.win32-py3.3. exe from here: lfd.uci.edu/~gohlke/pythonlibs/ this installed in C:\python33\Lib\site-packages.
I added C:\python33 to the win path and C:\python33\Lib\site-packages

created file1.py
contents
Code: Select all
import pyodbc as p

So here are results now:
call file from command line:
Code: Select all
C:\>file1.py
Traceback (most recent call last):
  File "C:\file1.py", line 1, in <module>
    import pyodbc as p
ImportError: No module named pyodbc
C:\>


call python and pass file from command line : no errors
Code: Select all
C:/>python files.py

C:/>


run in python shell : no errors
Code: Select all
C:/>python
>>>import pyodbc as p
>>>


wondering if I forgot something during install?
thanks again
james
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm

Re: problem with pyodbc import

Postby metulburr » Wed Jun 26, 2013 7:42 pm

I know, I know.. I just get tired of spending days trying to get this module or that compiler or that web server to work right... sigh...

I reinstall my Ubuntu OS every 6 months at least. which the same process got very boring for me as well. That is why i made a script to auto do this sort of stuff for me every time i reinstall an Ubuntu OS.
https://github.com/metulburr/distro_setup
You could make one for windows to so whatever 3rd party modules you prefer.


Code: Select all
C:\>file1.py

This is not going to do anything. You are not invoking python at all.

If your trying to make the script executable in windows:
http://logix4u.net/component/content/ar ... hon-script
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1383
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: problem with pyodbc import

Postby dogdaynoon » Wed Jun 26, 2013 10:54 pm

This is not going to do anything. You are not invoking python at all.


oh...
man, i've been staring at this to long...
dogdaynoon
 
Posts: 12
Joined: Thu May 23, 2013 11:56 pm


Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], szostakowicz and 2 guests