I have been using Visual Studio Code to develop some python programs. Modules that I import include numpy and cssutils. Sometimes VS CODE asked for upgrade that I usually agreed. Then today, VS CODE suddenly cannot find cssutils. I and my students checked all the environment variables, path variables, and surveyed the internet, but couldn't find any clue. Some people said it is a VS CODE bug that the authors claimed has been fixed but actually not. Some people suggests adding some declaration to the launch.json file and setting.json.
We tried all and none worked. We have also shut down the PC and rerun vscode.
Finally, we uninstalled cssutils and pip install it again. Then the problem became that numpy cannot be imported. Then we tried all the methods listed in the above and surveyed the internet. We also decide to uninstall and reinstall vs code. But none worked.
Can someone help ?
We have tried the following:
pip installed numpy
pip3 installed numpy
pip uninstalled numpy and then pip installed it.
We checked the path of the python interpreter in vs code environment settings.
We tried adding #{workspaceRoot} to the environment attribute in launch file.
We tried relaunching vs code.
We tried shut down the computer and then powered it on again.
We tried to reinstall vs code.
But none of the above worked.
We also tried importing numpy in powershell and it worked fine.
PS C:\Users\XXXXXXXXXXXXXXXXXXX> & 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe' 'c:\Users\FARN\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py' '--default' '--client' '--host' 'localhost' '--port' '50166' 'C:\Users\XXXXXXXXXXXXXXXXXXX/src/CnTaaD.py' '-L'
python 3.x
1.here: C:\Users\XXXXXXXXXXXXXXXXXXXXXXX
T0, starting testing task: <CnUserManager.CnUserManagerClass object at 0x000001BAC67866A0>
CnServerConnector: rootDir = C:\Users\XXXXXXXXXXXXXXXXXXXXXXXX
FM cmdLineJsonFilePath: C:\Users\XXXXXXXXXXXXX\YYYYYYYY.json
try opening file in python 3 in utf8!
try loading json file!
success in loading json file: <_io.TextIOWrapper name='C:\\Users\\XXXXXXXXXXXXXXXXXX\\YYYYYYY.json' mode='r' encoding='utf8'>
After loading the recorded projects json!
icoPath: C:\Users\XXXXXXXXXXXXXXXXX\src\pictures\animation\setDefault\logocute64.ico
---[ testerFrankWang02 userRecord already exists!]-------------------------
Traceback (most recent call last):
File "c:\Users\FARN\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Users\FARN\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
run()
File "c:\Users\FARN\.vscode\extensions\ms-python.python-2019.8.30787\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\FARN\Documents\LINUX\realtime\PRGM\TaaDPlaygroundClient/src/CnTaaD.py", line 35, in <module>
CnUserManager.CnUserManagerClass(sys.argv)
File "C:\Users\FARN\Documents\LINUX\realtime\PRGM\TaaDPlaygroundClient/src\CnUserManager.py", line 1334, in __init__
import CnProjectManager
File "C:\Users\FARN\Documents\LINUX\realtime\PRGM\TaaDPlaygroundClient/src\CnProjectManager.py", line 30, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
Press any key to continue . . .
It looks like you're using an installation of Python from Visual Studio instead of your own installed copy. Is that on purpose? And is that the installation of Python you installed numpy into?
The easiest way to see if numpy was installed where you expected is to run & 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\python.exe' '-m' 'pip' 'list' (that quoting might be wrong, but basically you want -m pip list passed to the Python interpreter). That will list what pip has installed.
The best solution to this is to use a virtual environment and install into that.
Related
I'm running Python 3.10.2288.0 (x64) on a Windows 10 OS.
I use IDLE as interpreter.
So far, I have been running IDLE (in and out venv) by:
C:path\to\venv venv\Scripts\Activate
(venv) C:path\to\venv python -m idlelib.idle
All of a sudden, this command didn't work anymore.
The following error appeared:
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\idlelib\idle.py", line 13, in <module>
from idlelib.pyshell import main # This is subject to change
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\idlelib\pyshell.py", line 53, in <module>
from idlelib import debugger
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\idlelib\debugger.py", line 7, in <module>
from idlelib import macosx
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\idlelib\macosx.py", line 7, in <module>
from test.support import requires, ResourceDenied
ModuleNotFoundError: No module named 'test'
I tried to reinstall Python, but nothing changed.
The same error appears when running command outside the venv.
It seems that everything is up-to-date.
What do you suggest?
Thanks,
idromv
This is the result of a buggy fix to a bug that is triggered when Python is installed without the test module. The bug appeared in 3.10.8 and 3.12.0a1, released a week ago, and at least in Microsoft Store Python 3.10.2288.0.
Omitting the test module seem to not currently be an option on Mac, so this should not be a problem there.
One fix anywhere is to edit /Lib/idlelib/macosx.py: delete line 7, from test.support import requires, ResourceDenied, and replace line 23, requires('gui') with pass. This may require admin privileges.
On Windows, rerun the python.org installer, chose Modify, and check the box to install the test suite.
For the Windows store Python, including the test suite may not be an option. One can, as mentioned in the comments, instead get the python.org installer and install with the test suite.
I don't know what the situation is for *nix.
I've spent the last few hours trying to install TensorFlow (non-GPU) and it still not working. I'm using Visual Studio 2019. I have used an admin CMD to pip install tensorflow, and it was successful (or seems so). I can see in %appdata%\..\Local\Programs\Python\Python37\Lib\site-packages\ that the folders tensorboard, tensorboard-2.0.1.dist-info, tensorflow, tensorflow_core, tensorflow_estimator, tensorflow_estimator-2.0.1.dist-info, and tensorflow-2.0.0.dist-info all exist. I ran pip multiple times to make sure that everything for TensorFlow was installed and up-to-date. I also followed the instructions in the installation guide for TensorFlow to verify the installation with python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))", which didn't give an error (also did not output anything, but I'm assuming it's not supposed to).
So I think my actual installation is fine, but perhaps this is a Visual Studio issue? Here's my Python code:
import tensorflow as tf
a = tf.Variable(1, name="a")
b = tf.Variable(2, name="b")
f = a + b
init = tf.global_variables_initializer()
with tf.Session() as s:
init.run()
print(f.eval())
As soon as I press "Start" to start the program, Visual Studio says "Exception Unhandled" and explains "module 'tensorflow' has no attribute 'global_variables_initializer'". The Python Console window then gives the following error:
Traceback (most recent call last):
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\ptvsd_launcher.py", line 119, in <module>
vspd.debug(filename, port_num, debug_id, debug_options, run_as)
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\debugger.py", line 39, in debug
run()
File "c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Users\[ME]\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\[ME]\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\[ME]\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\[ME]\Documents\Programming\Python\Tutorials\Simplest_Tensorflow_Application.py", line 8, in <module>
init = tf.global_variables_initializer()
AttributeError: module 'tensorflow' has no attribute 'global_variables_initializer'
When I hover my mouse over "tensorflow" in import tensorflow as tf, it VS says "TensorFlow root package". I'm not sure if that's what's supposed to be there or if the root package is something different.
If anyone has any suggestions on this, please let me know. I've tried for a while to get this to work and it's become rather frustrating. If anyone needs to know, I'm running a laptop with an SSD, 8GB DDR3 RAM, an Intel Core i7 3540M (Ivy Bridge) CPU, an integrated graphics card Intel HD Graphics 4000, and a dedicated graphics card NVIDIA NVS 5200M.
Even more information:
I had tried to install TensorFlow some time ago and had accidentally downloaded tensorflow and tensorflow-gpu. I have manually uninstalled them both through Visual Studio (which seemed to have removed them from the actual Python directory, not just in a virtual environment) and reinstalled just tensorflow.
I deleted and remade the VS solution. It seems Visual Studio was not updating its packages or something.
I am trying to make a plugin for QGIS 3(I am using Windows 10) but before it is created one step before it shows this message :
"The resource compiler pyrcc5 was not found in your path. You'll have to manually compile the resources .qrc file with pyrcc5 before installing your plugin".
This is a setback because after setting a plugin path in pyqgis it deploys but the plugin says it cannot find the class module.
I have managed to make a plugin but it says error when calling its classFactory() method thus i think this is because I fail to compile the pyrcc5.
It brings this error upon after selecting it couldn't load plugin 'remove_feature' due to an error when calling its classFactory() method :
ModuleNotFoundError: No module named 'remove_feature.resources'
Traceback (most recent call last):
File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python\qgis\utils.py", line 335, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "C:/Users/Arnold Kilaini M/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\remove_feature\__init__.py", line 35, in classFactory
from .Remove_feature import Remove_feature
File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python\qgis\utils.py", line 672, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/Arnold Kilaini M/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\remove_feature\Remove_feature.py", line 29, in
from .resources import *
File "C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python\qgis\utils.py", line 672, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
ModuleNotFoundError: No module named 'remove_feature.resources'
Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
QGIS version: 3.4.5-Madeira Madeira, 89ee6f6e23
Python Path:
C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python
C:/Users/Arnold Kilaini M/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/Arnold Kilaini M/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA~1/QGIS3~1.4/apps/qgis-ltr/./python/plugins
C:\Program Files\QGIS 3.4\bin\python37.zip
C:\PROGRA~1\QGIS3~1.4\apps\Python37\DLLs
C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib
C:\Program Files\QGIS 3.4\bin
C:\PROGRA~1\QGIS3~1.4\apps\Python37
C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\site-packages
C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\site-packages\win32
C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\site-packages\win32\lib
C:\PROGRA~1\QGIS3~1.4\apps\Python37\lib\site-packages\Pythonwin
C:/Users/Arnold Kilaini M/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:\Users\Arnold Kilaini M\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\mmqgis/forms
From the OSGeo4W Shell, run qt5_env.bat and py3_env.bat.
Then, change the directory to
C:\Users\Arnold Kilaini M\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\mmqgis".
Run pyrcc5 -o resources.py resources.qrc
Also, I found the link to a gis.stackexchange question related to yours:
Hope this helps!
With this .bat I don't have any problem aymore.
#echo off
SET QGIS_ROOT=C:\GIS\QGIS
call "%QGIS_ROOT%"\bin\o4w_env.bat
call "%QGIS_ROOT%"\apps\grass\grass78\etc\env.bat
path %PATH%;%QGIS_ROOT%\apps\qgis\bin
path %PATH%;%QGIS_ROOT%\apps\grass\grass78\lib
path %PATH%;C:\GIS\QGIS\apps\Qt5\bin
path %PATH%;C:\GIS\QGIS\apps\Python37\Scripts
set PYTHONPATH=%PYTHONPATH%;%QGIS_ROOT%\apps\qgis\python
set PYTHONPATH=%PYTHONPATH%;%QGIS_ROOT%\apps\Python37\lib\site-packages
set PYTHONHOME=%QGIS_ROOT%\apps\Python37
set QT_PLUGIN_PATH=%QGIS_ROOT%\apps\qgis\qtplugins;%QGIS_ROOT%\apps\qt5\plugins
set PATH=C:\Program Files\Git\bin;%PATH%
cmd.exe
for Ubuntu users, i tried this and it didn't work out:
pb_tool compile
also tied to install python-qt5 and Ubuntu 20.04 couldn't find it, then used
sudo apt install pyqt5-dev-tool
then pb_tool compile and it worked.
I have 64-bit Python (2.7.5) installed at C:\Python27 and 32-bit Python at C:\Python27_32.
I would like to use virtualenv to set up a 32-bit virtual environment that I can switch into when I need to use 32-bit Python. Once that environment is set up, I plan to edit the bin\activate file to change all the necessary paths to point to the 32-bit directories.
However, when I try to create the virtual environment, I get the following error:
> virtualenv --python=C:\Python27_32\python.exe foo
Running virtualenv with interpreter C:\Python27_32\python.exe
PYTHONHOME is set. You *must* activate the virtualenv before using it
New python executable in foo\Scripts\python.exe
Installing setuptools...............
Complete output from command C:\Users\<user>\Drop...o\Scripts\python.exe -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" C:\Python27\lib\site...ols-0.6c11-py2.7.egg:
Traceback (most recent call last):
File "<string>", line 278, in <module>
File "<string>", line 238, in main
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 21, in <module>
File "build/bdist.linux-i686/egg/setuptools/package_index.py", line 2, in <module>
File "C:\Python27\Lib\urllib2.py", line 94, in <module>
import httplib
File "C:\Python27\Lib\httplib.py", line 71, in <module>
import socket
File "C:\Python27\Lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: %1 is not a valid Win32 application.
----------------------------------------
...Installing setuptools...done.
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\virtualenv.py", line 2577, in <module>
main()
File "C:\Python27\lib\site-packages\virtualenv.py", line 979, in main
no_pip=options.no_pip)
File "C:\Python27\lib\site-packages\virtualenv.py", line 1091, in create_environment
search_dirs=search_dirs, never_download=never_download)
File "C:\Python27\lib\site-packages\virtualenv.py", line 611, in install_setuptools
search_dirs=search_dirs, never_download=never_download)
File "C:\Python27\lib\site-packages\virtualenv.py", line 583, in _install_req
cwd=cwd)
File "C:\Python27\lib\site-packages\virtualenv.py", line 1057, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command C:\Users\<user>\Drop...o\Scripts\python.exe -c "#!python
\"\"\"Bootstra...sys.argv[1:])
" C:\Python27\lib\site...ols-0.6c11-py2.7.egg failed with error code 1
It seems to be doing imports in the 64-bit folder instead of in the 32-bit folder. I'm not sure if it's because of the way my environment variables are set up, or because I installed virtualenv under 64-bit Python in the first place.
These are my user environment variables:
Path: %PYTHONHOME%;C:\Python27\Scripts
PYTHONHOME: C:\Python27
PYTHONPATH: C:\Python27\Lib;C:\Python27\Lib\lib-tk;C:\Python27\DLLs;
But if I change every C:\Python27 to C:\Python27_32 in my environment variables, then I can't virtualenv to run (ImportError: No module named pkg_resources).
This is my first time messing with virtualenv, so I'm sure I'm missing something basic. How can I create a virtual environment that uses my 32-bit Python installation?
For your virtual env to run after you have changed your paths you will need to install virtualenv into the 32 bit python - there is nothing stopping you having a copy of virtualenv in each python.
Assuming you have python 2.7.c 64-bit as your default python and you have also installed python 2.7.x 32-bit you would need both anyway - also assuming that you are on windows your two pythons will be installed somewhere like:
C:\Python27 and C:\Python27_64
With the latter on your path.
Also assuming that you have pip installed in both, you will need it for virtualenv anyway - to install virtualenv to the 32 bit python you can either run:
Path\To\32Bit\pip install virtualenv
or
set path=C:\Python27;C:\Python27\Scripts;%path%
rem The above should set your 32 bit to be found before your 64 bit
pip install virtualenv
If you installed the 32Bit version first, and install the 64Bit version second (And you added python to path), Then you can use the updated python launcher (py) to create the 64Bit version of your virtualenv
py -m venv my-env-name
in command prompt Use:
set CONDA_FORCE_32BIT=1
conda create -n virtualenv_name python=x.x anaconda
The above can be found # How to install win-32 package on a 64-bit system with conda install I personally tried it and it worked successfully (32-bit python x.x installed). Using Anaconda is not necessary but it will install all of the anaconda packages like pandas.
Disclaimer: The comment below is a caution and not an attack on the answer submitted by anyone else.
As my friend told me "changing the path manually is discouraged, mostly because you'd have to inform other applications that use Python (and that you do not necessarily know of) to point to a different folder, and changes are not certain to be consistent across your system. In a way, virtualenvs do the same but in a cleaner and (sort of) predictable fashion".
I am new to Python and also Google App Engine, but I am stuck up with the installations of it and its compatibility. I am using mac os -x and eclipse helios and got the pyDev plugin installed but in spite of all this i am still getting errors. . .
Whenever I try to import PIL from the terminal it does not give me any errors meaning that it was installed successfully but when I use the same Import in the eclipse file. I getting the compilation error as:
"Unresolved Import"
Please help me with this
Somehow I tried to fix that, then it gives me the error saying that imaging : no matching architecture in universal wrapper
when I changed the architecture to 32 bit ti gives me this in Eclipse Log :
Traceback (most recent call last):
File "/Users/Vinay/Documents/EclispeHeliosWorkspace/helloworld/Main.py", line 7, in <module>
im.show()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py", line 1483, in show
_show(self, title=title, command=command)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py", line 2123, in _show
apply(_showxv, (image,), options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py", line 2127, in _showxv
apply(ImageShow.show, (image, title), options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageShow.py", line 41, in show
if viewer.show(image, title=title, **options):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageShow.py", line 66, in show
self.show_image(image, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageShow.py", line 85, in show_image
return self.show_file(self.save_image(image), **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageShow.py", line 81, in save_image
return image._dump(format=self.get_format(image))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py", line 488, in _dump
self.load()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageFile.py", line 164, in load
self.load_prepare()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/ImageFile.py", line 231, in load_prepare
self.im = Image.core.new(self.mode, self.size)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/Image.py", line 37, in __getattr__
raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed
What do I do :( ?
PIL has some specific instructions for installation. Have you seen them?
Installing PIL on GAE
Download the PIL .dmg file. For example, you can download the PIL 1.1.6 .dmg file from http://pythonmac.org/packages/py25-fat/index.html.
Double-click on the installer to start the installation process.
Choose the correct directory. Finish the installation.
This is just for use in your local development environment. When you upload it'll use a GAE supplied version of PIL which means you also have to update your app.yaml file like so:
libraries:
- name: PIL
version: "1.1.7"
as detailed here.
IIRC You will want to install it "inside" your application directory itself so it can be accessed by your application locally. Not sure about that on the MAC however.
I just installed Pillow (using: sudo pip install Pillow) to get PIL in Python 2.7.6 on OS X 10.8.5 Mountain Lion.
I had the same issue in PyDev with Eclipse Kepler. To fix:
Go to:
Eclipse -> Preferences -> PyDev -> Interpreter - Python -> Libraries and click on "New Folder."
Then navigate to:
/Library/Python/2.7/site-packages
and click Open, and then Apply, then OK.
Then I quit Eclipse and restarted -- problem fixed. :)