I am trying to import pyodbc module on a windows computer. It works in the terminal, but not the IDLE. The error message in IDLE is:
Traceback (most recent call last):
File "FilePath/Filename.py", line 3, in <module>
import pyodbc
ImportError: No module named pyodbc
This typically occurs when multiple versions of python are installed with different paths. You can check to see if you have multiple installations by opening up the IDLE terminal and using
import sys
sys.version
sys.path
These commands will print the system PATH and version of the current instance of python. Use this in both IDLE and the command line terminal to see where each differ. Once you know which version is the one you want then just remove the other. You could also remove all python instances and then reinstall a clean python environment but then you would have to re-install all of your modules using pip or easy_install
Open python in cmd (type python and press enter)
Import the module in cmd (type import modulename)
Type modulename.__file__
You will get the path where the module is stored
Copy the corresponding folder
In IDLE, import sys and typing sys.executable to get the paths where it looks for modules to import
Paste your module's folder in the path where IDLE looks for modules.
This method worked for me.
You can pip show after install package and know about location where package installed.
After that check in IDLE sys.path and if directory with package not in sys.path try to add it.
import sys
sys.path.append("/home/dm/.local/lib/python3.6/site-packages")
# or another folder that `pip show` about package.
this happen because of multiple python installed (32bit version, 64bit version) or 3v and 2.7v so to solve this problem you have to invoke the idle for that specific version like this
cd to the dir of the version that the import work fine in cmd in that folder type this command below
pythonw.exe Lib\idlelib\idle.pyw
this command will invoke idle for that version
and the import will work fine
Me too had the same issue while trying to import a module which was successfully imported on terminal and not able to install on IDLE.
How I fixed?
Assuming you know how to execute commands on terminal as well as inside of python interpreter
Open your Terminal & execute the below commands :
:~$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>> import sys
>>> sys.version
'3.6.9 (default, Jan 26 2021, 15:33:00) \n[GCC 8.4.0]'
>>> sys.path
['', '/usr/lib/python36.zip', '/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload', '/usr/local/lib/python3.6/dist-
packages', '/usr/lib/python3/dist-packages']
>>>
Now import your module inside of your python3 interpreter.
>>> import nester
>>>
>>> nester.__file__
'/usr/local/lib/python3.6/dist-packages/nester.py'
>>>
Open your IDLE and run the below commands and compare them
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more
information.
>>> import sys
>>> sys.version
'3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit
(AMD64)]'
>>> sys.path
['','C:\Users\username\AppData\Local\Programs\Python\Python39\Lib\idlelib', 'C:\Users\username\AppData\Local\Programs\Python\Python39\python39.zip', 'C:\Users\username\AppData\Local\Programs\Python\Python39\DLLs', 'C:\Users\username\AppData\Local\Programs\Python\Python39\lib', 'C:\Users\username\AppData\Local\Programs\Python\Python39', 'C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages']
>>> sys.executable
'C:\Users\username\AppData\Local\Programs\Python\Python39\pythonw.exe'
Now if you compare both outputs from Terminal & IDLE,
Terminal Module location is different from IDLE
I was using Ubuntu 18 terminal on windows machine
So I just copied my file to 'C' directory and ensured its file privileges. That's it.
:~$ cp -p /usr/local/lib/python3.6/dist-packages/nester.py /mnt/c/Users/username/AppData/Local/Programs/Python/Python39/Lib/
It worked!!
I Found the solution. It works for me
The problem is your installation directory does not match with the python version directory.
solution is >>>
type %localappdata% in your search bar then go to this folder.
here select the program folder. then select Programs , Python , Python version , Scripts
copy the location of the Scripts folder
open command prompt and type cd //yourpath (in my case cd C:\Users\3C HOUSE\AppData\Local\Programs\Python\Python37\Scripts)
if you wanna install numpy , now run pip install numpy
When you put your python scripts that have import pandas in the same folder as the site packages like pandas for example and use the same version of python that is used on CMD, it should help run your scripts in IDLE.
Check the path of your code, and that of the module. Copying the module to the path where code is worked for me.
'sys.executable' will give the path where code is stored.
For windows, open command prompt and enter pip show pyodbc to get the path of package and copy the path.
then open idle and run these lines
import sys
sys.path
Match the path from command prompt and the paths mentioned in the list provided by running above lines in IDLE. If the path is not mentioned then run these lines in idle
sys.path.append("Enter the copied path of package here")
After executing these lines, check again by importing the package that if it works for you.
I have in myFile.py:
import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
import rospy
I do have ros package in ros env
(ros) $ pip list | grep rospy
rospy 1.11.21
rospy-message-converter 0.4.0
If I run this file from IDEA after setting up ros conda env
/home/username/anaconda3/envs/ros/bin/python /home/username/Projects/Python/myProject/myFile.py
['argparse==1.4.0', 'catkin-pkg==0.4.9', 'certifi==2018.10.15', 'docutils==0.14', 'numpy==1.15.4', 'pip==18.1', 'pyparsing==2.3.0', 'python-dateutil==2.7.5', 'python==2.7.15', 'pyyaml==3.13', 'rospkg==1.1.7', 'setuptools==40.6.2', 'six==1.11.0', 'wheel==0.32.3', 'wsgiref==0.1.2']
Traceback (most recent call last):
File "/home/username/Projects/Python/myProject/myFile.py", line 8, in <module>
import rospy
ImportError: No module named rospy
Process finished with exit code 1
I used the following configuration:
However, if I run the same on terminal, it just works:
On terminal, even without conda activate ros:
$ /home/username/anaconda3/envs/ros/bin/python /home/username/Projects/Python/myProject/myFile.py
['actionlib==1.11.13', 'angles==1.9.11', 'argparse==1.4.0', 'base-local-planner==1.12.16', 'bondpy==1.7.20', 'camera-calibration-parsers==1.11.13', 'camera-calibration==1.12.23', 'camera-info-manager-py==0.2.3', 'capabilities==0.2.0', 'catkin-pkg==0.4.9', 'catkin==0.6.19', 'certifi==2018.10.15', 'controller-manager-msgs==0.9.7', 'controller-manager==0.9.7', 'create-dashboard==2.3.1', 'create-driver==2.3.0', 'create-node==2.3.0', 'cv-bridge==1.11.16', 'diagnostic-analysis==1.9.3', 'diagnostic-common-diagnostics==1.9.3', 'diagnostic-updater==1.9.3', 'docutils==0.14', 'dynamic-reconfigure==1.5.49', 'gazebo-plugins==2.4.16', 'gazebo-ros==2.4.16', 'gencpp==0.5.5', 'genlisp==0.4.15', 'genmsg==0.5.8', 'genpy==0.5.10', 'image-geometry==1.11.16', 'interactive-markers==1.11.3', 'kobuki-dashboard==0.4.2', 'laser-geometry==1.6.4', 'message-filters==1.11.21', 'numpy==1.15.4', 'openni2-launch==0.4.1', 'pip==18.1', 'pluginlib==1.10.7', 'pyparsing==2.3.0', 'python-dateutil==2.7.5', 'python-qt-binding==0.2.19', 'python==2.7.15', 'pyyaml==3.13', 'qt-dotgraph==0.2.33', 'qt-gui-cpp==0.2.33', 'qt-gui-py-common==0.2.33', 'qt-gui==0.2.33', 'resource-retriever==1.11.8', 'rocon-app-manager==0.7.13', 'rocon-app-utilities==0.7.13', 'rocon-apps==0.7.13', 'rocon-console==0.1.23', 'rocon-ebnf==0.1.23', 'rocon-gateway-utils==0.7.10', 'rocon-gateway==0.7.10', 'rocon-hub-client==0.7.10', 'rocon-hub==0.7.10', 'rocon-interactions==0.1.23', 'rocon-launch==0.1.23', 'rocon-master-info==0.1.23', 'rocon-python-comms==0.1.23', 'rocon-python-redis==0.1.23', 'rocon-python-utils==0.1.23', 'rocon-python-wifi==0.1.23', 'rocon-qt-library==0.7.12', 'rocon-remocon==0.7.12', 'rocon-semantic-version==0.1.23', 'rocon-uri==0.1.23', 'rosbag==1.11.21', 'rosboost-cfg==1.11.14', 'rosclean==1.11.14', 'roscreate==1.11.14', 'rosgraph==1.11.21', 'roslaunch==1.11.21', 'roslib==1.11.14', 'roslint==0.10.0', 'roslz4==1.11.21', 'rosmake==1.11.14', 'rosmaster==1.11.21', 'rosmsg==1.11.21', 'rosnode==1.11.21', 'rosparam==1.11.21', 'rospkg==1.1.7', 'rospy-message-converter==0.4.0', 'rospy==1.11.21', 'rosservice==1.11.21', 'rostest==1.11.21', 'rostopic==1.11.21', 'rosunit==1.11.14', 'roswtf==1.11.21', 'rqt-action==0.4.9', 'rqt-bag-plugins==0.4.8', 'rqt-bag==0.4.8', 'rqt-console==0.4.8', 'rqt-dep==0.4.9', 'rqt-graph==0.4.8', 'rqt-gui-py==0.4.8', 'rqt-gui==0.4.8', 'rqt-image-view==0.4.9', 'rqt-launch==0.4.8', 'rqt-logger-level==0.4.8', 'rqt-moveit==0.5.7', 'rqt-msg==0.4.8', 'rqt-nav-view==0.5.7', 'rqt-plot==0.4.8', 'rqt-pose-view==0.5.8', 'rqt-publisher==0.4.8', 'rqt-py-common==0.4.8', 'rqt-py-console==0.4.8', 'rqt-reconfigure==0.4.10', 'rqt-robot-dashboard==0.5.7', 'rqt-robot-monitor==0.5.7', 'rqt-robot-steering==0.5.9', 'rqt-runtime-monitor==0.5.7', 'rqt-rviz==0.5.7', 'rqt-service-caller==0.4.8', 'rqt-shell==0.4.9', 'rqt-srv==0.4.8', 'rqt-tf-tree==0.5.8', 'rqt-top==0.4.8', 'rqt-topic==0.4.10', 'rqt-web==0.4.8', 'rviz==1.11.19', 'sensor-msgs==1.11.10', 'setuptools==40.6.2', 'six==1.11.0', 'smach-ros==2.0.1', 'smach==2.0.1', 'smclib==1.7.20', 'tf-conversions==1.11.9', 'tf2-geometry-msgs==0.5.17', 'tf2-kdl==0.5.17', 'tf2-py==0.5.17', 'tf2-ros==0.5.17', 'tf2-sensor-msgs==0.5.17', 'tf==1.11.9', 'unique-id==1.0.5', 'warehouse-ros==0.8.8', 'wheel==0.32.3', 'world-canvas-client-py==0.1.0', 'world-canvas-server==0.1.0', 'world-canvas-utils==0.1.0', 'wsgiref==0.1.2', 'xacro==1.9.5']
So IDEA is not executing the printed command? Is it running something else? Why do I see way less installed packages for the conda env ros running from inside IDEA and how do I resolve this issue?
I'm on
IDEA 2018.3
Ubuntu 14.04
Update:
I have configured the conda env and I verified it like this:
On terminal:
$ conda activate ros
(ros) $ python
Python 2.7.15 |Anaconda, Inc.| (default, Nov 13 2018, 23:04:45)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.executable)
/home/username/anaconda3/envs/ros/bin/python
On Python Console from IDEA > Tools > Python Console
PyDev console: starting.
Python 2.7.15 |Anaconda, Inc.| (default, Nov 13 2018, 23:04:45)
[GCC 7.3.0] on linux2
import sys
print(sys.executable)
/home/username/anaconda3/envs/ros/bin/python
When you tried to run this script in the system terminal (outside of IDEA), were you using the same interpreter? If not, please try again but use the same interpreter you use in IDEA. Do you have the same error?
If not, try the following:
run import os in the system terminal using the same interpreter
run print(os.environ['PATH'])
copy the result and add as PATH environment variable to your Run/Debug Configuration
I have a list of python scripts which run perfectly fine through idle. However, when I run it through cmd I get various errors stating
No module named 'selenium',
,No module named 'googletrans'
,No module named 'tabula'
When I use pip install it says.
'Requirement already satisfied'
Also when I check pip list the above mentioned modules are there.
sys.path
In cmd
['', 'C:\Users\jay.haran\Documents\PC_scrape\Scraper', 'C:\Users\jay.haran\ C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\Lib\idlelib', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\python36.zip', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\DLLs', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\lib', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\lib\site-packages']
'I added the second and third item in the list
In idle
['C:\Users\jay.haran\Documents\PC_scrape\Scraper', 'C:\Users\jay.haran\Documents\PC_scrape\Scraper', 'C:\Users\jay.haran\Documents\PC_scrape\Scraper\ C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\Lib\idlelib', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\python36.zip', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\DLLs', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\lib', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32', 'C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\lib\site-packages']
sys.version
In both
In cmd and In idle = 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)]
sys.executable
In cmd = C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\python.exe
In idle = C:\Users\jay.haran\AppData\Local\Programs\Python\Python36-32\pythonw.exe
There are other modules installed such as bs4, xlrd, pandas that aren't causing any issues.
Thank you very much for any help.
There’s a project where I need to use both Python 3.3 and 2.7. I am trying to launch a script under Python 2.7 but it’s not working. Here is a simple example.
first.py
import subprocess
import sys
print('Inside first.py')
print(sys.version)
subprocess.Popen(["C:\Python27\ArcGISx6410.2\Python.exe", "second.py"])
second.py
import arcpy
print 'This is second.py'
This doesn’t work and the output is
Inside first.py
3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)]
File "C:\Python33\lib\site.py", line 173
file=sys.stderr)
^
SyntaxError: invalid syntax
That’s the entire stack trace. If I were to replace C:\...Python.exe with notepad.exe then it works. I’m using Liclipse on Windows 7.
UPDATE: it appears different versions of Python are run, when from the command line python first.py is 3.3 but py first.py or just first.py then 2.7 is used.
Try:
import os
subprocess.Popen(["C:\\Python27\\ArcGISx6410.2\\Python.exe", "second.py"], env=dict(os.environ, PYTHONHOME="C:\\Python27\\ArcGISx6410.2"))
Python on Windows needs a little help sometimes to figure out which version of the standard library to use.
I tried to install cx_Oracle from pypi source since there is no available port for it in cygwin. I did make some changes as suggested in http://permalink.gmane.org/gmane.comp.python.db.cx-oracle/2492 and modified my setup.py. However, I still get the following error :-
$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
/usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-py2.7-cygwin-1.7.24-i686.egg/cx_Oracle.py:3: UserWa
rning: Module cx_Oracle was already imported from /usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-p
y2.7-cygwin-1.7.24-i686.egg/cx_Oracle.pyc, but /home/zerog/cx_Oracle-5.1.3 is being added to sys.pat
h
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.cygwin-1.7.24-i686/egg/cx_Oracle.py", line 7, in <module>
File "build/bdist.cygwin-1.7.24-i686/egg/cx_Oracle.py", line 6, in __bootstrap__
ImportError: Exec format error
>>>
If someone can please help me fix this ?
TIA.
Fixed this by specifying the path to instantclient as below :
$ export PATH=$PATH:/cygdrive/d/Tools/instantclient_11_2
(Other, possibly important stuff) :
$ echo $LD_LIBRARY_PATH
/cygdrive/d/Tools/instantclient_11_2
$ echo $ORACLE_HOME
/cygdrive/d/Tools/instantclient_11_2
Now, I get :-
$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>>
It's hard to pin down from the error message alone, but I am guessing that you have two different copies of cx_Oracle in your sys.path. The error message is complaining that a different version of the same module had already been import-ed.
Presumably the pristine upstream version is installed system-wide in /usr/lib/python2.7/site-packages/cx_Oracle-5.1.3-py2.7-cygwin-1.7.24-i686.egg, and your modified version in /home/zerog/cx_Oracle-5.1.3.
Does it work if you pare down sys.path so that only the original, or only your modified version, is included?
(You might want to use virtualenv if you need to switch back and forth between two versions frequently.)
I ran into this error "Exec format error."
For me, this was likely caused by a mismatch between cygwin being installed as 64 bit, but the instant client being installed as 32 bit. Double check that everything (oracle, cygwin) is either 32 bit or 64 bit.
What fixed my issue:
Since my cygwin is 64 bit (see uname -a, and look for x86_64), I downloaded the 64 bit instant client from oracle's website, and unzipped
I set the env vars in .profile, to point where it was unzipped:
export ORACLE_HOME=/cygdrive/c/oracle/instantclient_x64_11_2
export LD_LIBRARY_PATH=$ORACLE_HOME
export DYLD_LIBRARY_PATH=$ORACLE_HOME
export TNS_ADMIN='//optional/path/to/your/oracle/tns/files/'
source ~/.profile
To test, you should now be able to run this python command with no error:
import cx_Oracle
To verify the path is correct, if you run ls, you should see something like
ls $ORACLE_HOME
adrci.exe genezi.exe oci.sym ociw32.dll ojdbc6.jar
oraocci11.dll oraociei11.sym uidrvci.exe vc9
adrci.sym genezi.sym ocijdbc11.dll ociw32.sym orannzsbb11.dll
oraocci11.sym orasql11.dll uidrvci.sym xstreams.jar
BASIC_README oci.dll ocijdbc11.sym ojdbc5.jar orannzsbb11.sym
oraociei11.dll orasql11.sym vc8