Why did installing VS break Python scripts from running at Command Prompt? - python

I'm using Python 3.7. I've installed a few packages using pip install. I usually run the scripts I've written directly from the command line, in the Windows Command Prompt.
The other day I installed Visual Studio 2019 Community Edition, mainly for coding C++ console apps. While installing, I noticed it has support for Python, so I checked the box to include the Python features of Visual Studio. I've done nothing further with respect to configuring VS.
Now, when I try to run my Python scripts from the command line, I get a ModuleNotFoundError. For example:
C:\Users\me\Python\MyScript.py
Traceback (most recent call last):
File "C:\Users\me\Python\MyScript.py", line 25, in <module>
import pyvisa.errors
ModuleNotFoundError: No module named 'pyvisa'
Here are the import statements at the top of my script:
# System imports
import sys
import os
import re
import argparse
from enum import Enum
# Third-party library imports
import pyvisa.errors
import pyvisa as visa
The library in question is still installed:
C:\Users\me\Python>pip show pyvisa
Name: PyVISA
Version: 1.10.1
Summary: Python VISA bindings for GPIB, RS232, TCPIP and USB instruments
Home-page: https://github.com/pyvisa/pyvisa
Author: Torsten Bronger, Gregor Thalhammer
Author-email: bronger#physik.rwth-aachen.de
License: MIT License
Location: c:\users\me\appdata\local\programs\python\python37-32\lib\site-packages
Requires:
Required-by:
My path and PYTHONPATH are:
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Users\me\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\me\AppData\Local\Programs\Python\Python37-32\;C:\Users\me\AppData\Local\Microsoft\WindowsApps;
PYTHONPATH=C:\Users\me\Python\pkg
Here is the sys.path:
C:\Users\me\Python>python -m site
sys.path = [
'C:\\Users\\me\\Python',
'C:\\Users\\me\\Python\\pkg',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\python37.zip',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\DLLs',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\lib',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages',
'C:\\Users\\me\\Python\\common',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\win32\\lib',
'C:\\Users\\me\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-p`enter code here`ackages\\Pythonwin',
]
USER_BASE: 'C:\\Users\\me\\AppData\\Roaming\\Python' (doesn't exist)
USER_SITE: 'C:\\Users\\me\\AppData\\Roaming\\Python\\Python37\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True
I've read several of the top Google hits for ModuleNotFoundError, but a simple explanation is not to be found.
What is a straightforward solution to this?

Related

How to specify correct version of a python module

I have a container with two versions of scapy python modules installed. One 2.2.0-dev installed from sources by this project that I install. It comes with 2.2.0-dev bundled with it. I'm trying to figure out if skipping its installation would break anything.
Also, I use pip and install scapy (pip2 install scapy)
This results in having 2.4.3 installed.
Now when I have this sample script s.py written as shown below, it seems to load from /usr/lib/python2.7/site-packages/scapy/ where the VERSION file says 2.4.3 but later when I call interact() it says version 2.2.0-dev. Is there a proper way I can force import of the 2.4.3 modules?
$ cat s.py
import scapy
print(scapy)
print(scapy.__file__)
from scapy.main import interact
interact()
$ python s.py
<module 'scapy' from '/usr/lib/python2.7/site-packages/scapy/__init__.pyc'>
/usr/lib/python2.7/site-packages/scapy/__init__.pyc
INFO: Can't import python gnuplot wrapper . Won't be able to plot.
INFO: Can't import PyX. Won't be able to use psdump() or pdfdump().
WARNING: No route found for IPv6 destination :: (no default route?)
INFO: Can't import python Crypto lib. Won't be able to decrypt WEP.
INFO: Can't import python Crypto lib. Disabled certificate manipulation tools
Welcome to Scapy (2.2.0-dev)
>>>
$ cat /usr/lib/python2.7/site-packages/scapy/VERSION
2.4.3

ImportError _versionhelper when setting up Bloomberg Python API

I am trying to get set up with the Bloomberg Python API. I have been following along with this tutorial. I am able to successfully python -m pip install — index-url=https://bloomberg.bintray.com/pip/simple blpapi, but then when I try to run import blpapi in the Python interpreter, I get the following error. How do I resolve this error (wondering if it has something to due with me using Python 3.8)?
ImportError:
---------------------------- ENVIRONMENT -----------------------------
Platform: Windows-10-10.0.17763-SP0
Architecture: ('32bit', 'WindowsPE')
Python: 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]
Python implementation: CPython
blpapi 64-bit will be loaded from: "C:\blp\API\blpapi_cpp_3.13.1.1\lib\blpapi3_64.dll"
blpapi 32-bit will be loaded from: "C:\blp\API\blpapi_cpp_3.13.1.1\lib\blpapi3_32.dll"
System PATH: (* marks locations where blpapi was found)
"C:\Windows\system32"
"C:\Windows"
"C:\Windows\System32\Wbem"
"C:\Windows\System32\WindowsPowerShell\v1.0\"
"C:\Windows\System32\OpenSSH\"
"C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL"
"C:\Program Files\Intel\Intel(R) Management Engine Components\DAL"
"c:\nx_dll"
"C:\Program Files\nodejs\"
* "C:\blp\API\blpapi_cpp_3.13.1.1\lib"
"C:\Program Files\MiKTeX 2.9\miktex\bin\x64\"
"C:\Users\cpage\AppData\Local\Programs\Python\Python38-32\Scripts\"
"C:\Users\cpage\AppData\Local\Programs\Python\Python38-32\"
"C:\Users\cpage\AppData\Local\Microsoft\WindowsApps"
* "C:\blp\DAPI"
"C:\blp\DAPI\DDE"
"C:\Users\cpage\AppData\Roaming\npm"
"C:\Program Files\Sublime Text 3"
"C:\Users\cpage\AppData\Local\hyper\app-3.0.2\resources\bin"
"C:\Users\cpage\AppData\Local\Programs\Microsoft VS Code\bin"
* "C:\blp\API\blpapi_cpp_3.13.1.1\lib"
blpapi package at: "C:\Users\cpage\AppData\Local\Programs\Python\Python38-32\lib\site-packages"
Current directory: "C:\Users\cpage"
----------------------------------------------------------------------
No module named '_versionhelper'
Could not open the C++ SDK library.
Download and install the latest C++ SDK from:
http://www.bloomberg.com/professional/api-library
If the C++ SDK is already installed, please ensure that the path to the library
was added to PATH before entering the interpreter.
You need to download the python blpapi package having the version matching your C++ lib.
In your case, since your C++ lib is 3.13.1.1, you can download the 3.13.1 python package:
pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi==3.13.1
Just managed to make it run using version blpapi-3.15.2 using C++ API blpapi_cpp_3.15.0.1
To install run:
python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi
to import use:
import os
with os.add_dll_directory('<...>\blpapi_cpp_3.15.0.1\lib'):
import blpapi
or add '<...>\blpapi_cpp_3.15.0.1\lib' to PATH
The following procedure works out of the box for CPython 2.7 and 3.7. A Bloomberg rep claims he verified it for CPython 3.5 as well:
Download the C++ BLP API from the official Bloomberg repository. If this link breaks, use Bloomberg API Support homepage to find the up-to-date ones.
Unpack the archive to C:\Programs\blpapi_cpp_3.14.3.1
Exit from the shell.
Set the environment variable BLPAPI_ROOT=C:\Programs\blpapi_cpp_3.14.3.1\. Note that the trailing slash is important.
Start a new shell.
Execute python -m pip install --index-url=https://bloomberg.bintray.com/pip/simple blpapi==3.14.0
Check the installation by executing python -c "import blpapi", which should pass without displaying messages.

Running SikuliX 1.1.4 Python scripts from Command Line

I have some Python (jython actually) scripts that run with Sikulix.
I was previously using version 1.1.1 and was using the command line (after doinmg the setup):
java -Dsikuli.Debug=-2 -cp sikulix.jar org.python.util.jython main.py
With version 1.1.4, there is no more setup, and jython has been removed from sikulix.jar and sikulixapi.jar. Jython is in another jar file (jython-standalone-2.7.1.jar).
I tried to run with following command line
java -Dsikuli.Debug=-2 -cp "sikulix.jar;jython-standalone-2.7.1.jar" org.python.util.jython main.py
But I get the following error
Traceback (most recent call last):
File "test.py", line 3, in <module>
from sikuli.Sikuli import *
ImportError: No module named sikuli
The documentation is not fully updated on how to do it. They mention installation of jython, jip and other stuff but nothing managed to work.
Any idea on how to do it?
Thanks
==PS==:
After doing the following it almost worked:
Installing jython
Setting CLASSPATH to absolute path of sikulixapi.jar
Running jython main.py
I got the following error:
[error] RunTimeINIT: *** terminating: Java arch not 64 Bit or not detected (java 8-32 version 1.8 vm 25.121-b13 class 52.0 arch null)
I have installed Jython with a 32-bits Java and it seems 64-bits Java is required.
I will probably try again with 64-bits Java JDK.
Add the following line at the beginning of your script
import org.sikuli.script.SikulixForJython
This will help to look for sikuli module in Java classes.
You can then run with the command line mentionned previously:
java -cp "sikulixapi.jar;jython-standalone-2.7.1.jar" org.python.util.jython main.py
Example of Python script (main.py):
import org.sikuli.script.SikulixForJython
from sikuli.Sikuli import *
notepad = App('notepad.exe')
notepad.open()
sleep(1)
type("It is working!")
notepad.close()

Installing SIP for Python 2.7 on windows 10

I have seen many threads that have a high level of ambiguity and go off on tangents from the original question, often assuming much about the authors ability, so I am hoping that if I am direct and concise with my information, I will get an answer that is in line with the requirement. I know that the serious programmers will have seen this many times, in many formats, so please just bear with me as this is doing my head in. Please do not just post a link to some other answer as I rarely find that helps with my current issue.
I am not a hardcore programmer, I find the compiling, sourceball, tar, gz all nonsense to be honest and am looking for the easiest way to install sip for python on my machine. I have installed various versions of mingw32, mingw64 to the point that I don't know which one is best to use. I am assuming that the one here: C:\Program Files\mingw-w64 is the one, considering I am using 64 bit, but do the others I have installed impact on this?
I also installed versions of mysys:
C:\msys\1.0,
C:\msys64, but I still m unclear what and why etc, despite trying to read the docs that came with them.
I have windows 10, 64 bit professional edition.
I have python 2.7
I have installs of mingw, 32 bit and 64 bit in various locations, due mostly to not fully understanding what exactly it was or where it should go. I found zips of it and exes, so I got a bit confused.
I downloaded the sip package and unpacked it to here: C:\Python27\Lib\site-packages\sip-4.19.3 and it has the configure.py file in it. So far, so good.
I used a CMD window, changed directory to: C:\Python27\Lib\site-packages\sip-4.19.3 and then used the command: python configure.py to create the Makefile file which is what I believe is supposed to happen.
I then opened the mingw64 shell, changed directory to the above sip folder and typed: python configure.py again, just to be sure I would get a response and create the files again, probably should not have done so, but hey ho, at this point, I am quite frustrated with it and trying to do anything with what I have, which I know is poor practice. (see image 1.)
image 1: configure.py executed
From what I have read, I should use the make function that comes with Mingw64, but I tried the following, which also includes the configure.py code, but nothing seems to work when trying to use the Makefile file that was created via the configure.py process.
c:\Python27>cd ./Lib/site-packages/sip-4.19.3
c:\Python27\Lib\site-packages\sip-4.19.3> python configure.py
This is SIP 4.19.3 for Python 2.7.13 on win32.
The SIP code generator will be installed in C:\Python27.
The sip module will be installed in C:\Python27\Lib\site-packages.
The sip.pyi stub file will be installed in C:\Python27\Lib\site-packages.
The sip.h header file will be installed in C:\Python27\include.
The default directory to install .sip files in is C:\Python27\sip.
Creating siplib\sip.h...
Creating siplib\siplib.c...
Creating siplib\siplib.sbf...
Creating sipconfig.py...
Creating top level Makefile...
Creating sip code generator Makefile...
Creating sip module Makefile...
c:\Python27\Lib\site-packages\sip-4.19.3> Makefile
'Makefile' is not recognized as an internal or external command,
operable program or batch file.
c:\Python27\Lib\site-packages\sip-4.19.3> make Makefile
make: Nothing to be done for `Makefile'.
c:\Python27\Lib\site-packages\sip-4.19.3> Makefile Makefile
'Makefile' is not recognized as an internal or external command,
operable program or batch file.
c:\Python27\Lib\site-packages\sip-4.19.3>
So now I am at an impasse. I have the locations of my mingw versions and the msys in my path environment variable and I have done just about everything I have looked at on the web. I realise that its an order of things, but I really wish there were just executables for these modules and supporting tools as this compiling is a ball ache.I tried opening a python shell and importing sip.
>>> import os, sys
>>> import sip
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import sip
ImportError: No module named sip
>>> import sipconfig
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import sipconfig
ImportError: No module named sipconfig
>>> from sip import sip
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
from sip import sip
ImportError: No module named sip
>>> from sipconfig impport sip
SyntaxError: invalid syntax
>>> from sip import *
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
from sip import *
ImportError: No module named sip
So, if anyone has read through this and has a definitive answer as to what I am doing wrong, I would appreciate it.
make/nmake or make/nmake install cant be done from cmd and python path; instead using mingw or visual studio tools.
In windows search for prompt or Visual studio tools to open VS Command promt and from there cd--> sip file location (before this run configure.py present in sip folder)
Now run the commands nmake and then nmake install

GYB (got your back) Python install on Mac Yosemite triggers py2exe error

I would like to backup the contents of my gmail account.
A recommended solution is Python module:
https://github.com/jay0lee/got-your-back/releases
But within its setup.py file there is a reference to Windows py2exe, which triggers this message when I run setup.py install:
File "setup.py", line 2, in &LT;module>
import py2exe, sys, os
ImportError: No module named py2exe
As mentioned in the installation on mac page, you don't have to run setup.py to use the software :
Now run:
python gyb.py --email youremail#gmail.com --action estimate

Categories

Resources