ModuleNotFoundError: No module named 'docx' on VScode but not in Python itself - python-3.x

I have installed the python-docx module using pip:
python -m pip install python-docx
However, when I try to run my script that only contains import docx, I get the following error
ModuleNotFoundError: No module named 'docx'
When I execute the following command in Python on the command line, it works fine:
import docx

When using Visual Studio Code, make sure that it uses the same Python version as you are using when running the script. You you should set the "python.pythonPath" setting correctly in settings.json (manually edit the file or edit in Visual Studio itself). This can be done system-wide (per user), or per project.
Furthermore, this answer gives some background about how Python files are executed in Windows.

Related

Kivy Installation Guide for Windows 10

I've been trying to follow online youTube videos to install kivy on my Windows 10 computer (python-3.7.5-amd64, kivy 1.11.1). Aside from the fact that they seem to have different variations on how they approach the topic, I am unable to get a solution that operates satisfactorily.
These are the steps I am following:
I install python (python-3.7.5-amd64.exe) to C:\Python37
I modify the path to include to include the following: C:\Python37\Scripts;C:\Python37;C:\Python37\Libs;C:\Python37\DLLs;C:\Python37\Lib\site-packages;
I added the following environment variable PYTHONPATH = C:\Python37\DLLs;C:\Python37\Libs;C:\Python37;C:\Python37\Scripts;C:\Python37\Lib\site-packages;
I open a command window and type in the following commands (taken from kivy.org)
python -m pip install --upgrade pip wheel setuptools virtualenv
python -m pip install docutils pygments pypiwin32 kivy_deps.sdl2==0.1.* kivy_deps.glew==0.1.*
python -m pip install kivy_deps.gstreamer==0.1.*
python -m pip install kivy_deps.angle==0.1.*
python -m pip install kivy==1.11.1
python -m pip install kivy_examples==1.11.1
I try to run a simple program. From within Windows Explorer I right click the code file (label.py) and from the shortcut menu select python.
A windows pops up for an instant and a directory called __pycache__ gets created with kivy.cpython-37.pyc. Double clicking that causes the program to run.
Is it possible to have a easier solution in which the source code, once compiled executes?
If I open a command prompt and attempt to execute the source code using the command python label.py I get the following:
Traceback (most recent call last):
File "label.py", line 1, in <module>
from kivy.app import App
File "C:\Users\chrib\Google Drive\_Software\Python_Kivy\kivy.py", line 1, in <module>
from kivy.base import runTouchApp
ModuleNotFoundError: No module named 'kivy.base'; 'kivy' is not a package
Why should this happen?
Also is it possible to have a cleaner development environment. I am used to Visual Studio IDE and it would be great if I can use this environment.
Thanks
Code for label.py
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world!');
if __name__=='__main__':
MyApp().run();
I've been trying to follow online youTube videos to install kivy on my Windows 10 computer
Have you tried simply following the instructions on kivy.org? There's no need to use youtube videos, the installation is largely a normal python module install.
I try to run a simple program. From within Windows Explorer I right click the code file (label.py) and from the shortcut menu select python.
Don't do this, run the file by opening a command prompt and typing python yourfilename.py. That way you will see the full traceback for any errors that occur.
A windows pops up for an instant and a directory called pycache gets created with kivy.cpython-37.pyc. Double clicking that causes the program to run.
It sounds likely that the first run is crashing. As above, you want to get the information about why.
Is it possible to have a easier solution in which the source code, once compiled executes?
When you run the code it does execute. As above, it's probably crashing.
ModuleNotFoundError: No module named 'kivy.base'; 'kivy' is not a package
Have you made a file named kivy.py? It looks likely that you have, and that this file is being imported in preference to the installed kivy module.
Also is it possible to have a cleaner development environment. I am used to Visual Studio IDE and it would be great if I can use this environment.
I'm not sure what you consider unclean about your development environment, but you should think in terms of python environments and their installed packages. Kivy is just a python module that you install into a python environment. When you use an IDE, it may integrate with one or more python environments (with options to switch between them). There's nothing special about using Visual Studio with Kivy, just do whatever you normally do to use it with Python.
I figured it out. I had a program in the code directory called kivy.py. I renamed that and it worked.

How do I install curses library in my editor?

I cannot install the curses library in my Editor. Is there some other way to make sure I have the library installed and can import it?
I'm trying to build a tictactoe game using venv, in Pycharm Community Edition. I imported curses in the directory where my scripts are located using command prompt. I can import curses in IDLE editor. However, there is no package called curses in the Settings->Project Interpreter.
pip install curses‑2.2‑cp36‑cp36m‑win_amd64.whl
this throws an error:
Requirement 'curses-2.2-cp36-cp36m-win_amd64.whl' looks like a
filename, but the file does not exist
curses-2.2-cp36-cp36m-win_amd64.whl is not a supported wheel on this
platform.
Edited the configurations and checked the checkbox with emulate terminal in output console, still won't work.
You should use:
pip install https://download.lfd.uci.edu/pythonlibs/n5jyqt7p/curses-2.2.1+utf8-cp37-cp37m-win_amd64.whl
The section of the pip command line installer:
cp37 == CPython 3.7
So you need the appropriate whl install file for your installed Python environment.

Import Python Module into Sublime Text 3

I am trying to import Python modules (e.g. pandas or openpyxl) into Sublime Text 3.
I installed the modules on the command line using pip3 install. If I try to import the modules into the command line, they work. For instance,
import openpyxl
will run.
However, when I try the same on Sublime Text 3, I get the following error:
ModuleNotFoundError: No module named 'openpyxl'
How do I import those modules into Sublime Text 3?
It has been over a year since I asked this question myself. A few classes later into Command Line and Python I know 'somewhat' better what I am doing, and now came back to share the answer to this:
The problem here is that the versions of python that Sublime are using are not the same ones that my Command Line or my Jupyter Notebook are using. These 2 are using anaconda3/bin/python3. So the solution to this problem is to have Sublime use a Build that is pointing to this python (where the modules like openpyxl are installed).
On Sublime Text > Tools > Build System > New Build System...
Use this:
{
"cmd": ["path_to_your_desired_python_version", "-u", "$file"],
"file_regex": "^[ ]*File \"(…*?)\", line ([0–9]*)",
"selector": "source.python"
}
and change "path_to_your_desired_python_version" to point to your desired version of python.
Now save the build you just created, for example "Python3.7X.sublime-build".
From now on, you can select that build in Tool > Build Systems.
In my case, after creating a new build system, command+B can successfully import pygame, but F5 run still reported an error.
I checked the user file of the modified F5 hotkey in the ST and found that the BUILD path in it also needs to be changed, so it is solved by changing to the same python path as the newly created .sublime-build file.
I too had same problem. Couldn't import requests, pandas and some of other modules in sublime. I went to command prompt 'cmd', and first checked python version. If it shows you the version, that means python was installed correctly. Then i ran the command 'pip install requests'. This installed the requests module, and so i installed other ones as well. It's working fine since then on sublime.

Pyinstaller --onefile ImportError: No module named 'win32api'

Problem statement:
I can't seem to run
'PyInstaller --onefile myfile.py'
on a file containing
import wmi
It cannot find win32api. I get a popup warning saying python has stopped etc. My console says "ImportError: No module named 'win32api'". I can run 'import win32api', 'import win32com', and 'import WMI' in python directly in the same environment without issue. I fundamentally don't understand what is wrong here.
Error message:
3469 INFO: Loading module hook "hook-pywintypes.py"...
Fatal Python error: Py_Initialize: can't initialize sys standard streams
ImportError: No module named 'win32api'
I have tried:
PyInstaller - ImportError: No module named win32api - 'import os' works fine for PyInstaller and runs fine in python.
No module named 'win32api' - Not very helpful
How to install pywin32 module in windows 7 - This is where I got the SF link (python3.5 amd64 pywin32 version)
ImportError: no module named win32api -
I thought it might be a path thing, but my installation appears to be in the correct place: "C:\Users\myuser\AppData\Local\Continuum\Anaconda3\pkgs\pywin32-220-py35_2\Lib\site-packages\win32"
I can run 'PyInstaller --onefile myscript.py' on other files, and have without issue as long as they don't use the wmi module.
I looked at the win32com _init__.py line 5 where it's messing up and it's just an import statement for win32api.
System:
Windows 7 x64, Python 3.5.3 64bit, Anaconda 4.3.14 64bit, using pyinstaller 3.2.3 (recommended by this thread), with pywin32 220 (with sourceforge download [I know, I tried pip, conda, and easy_install]) and I'm running it in cmder as an admin.
In my case, I couldn't use the module in the python shell, even if original one could. When I execute python shell as an administrator option, it was solved. Try it with administrator execution. I used python version 3.5.2 with windows x64bits.
I face this problem but I install ---> pip install pypiwin32 to solve my problems

Pyinstaller Cannot find xlrd

I am running Python 3.5.1 and PyInstaller 3.2 on Windows.
I need to compile my script into an exe. I have done this with pyintaller before with different scripts and have had no issues. Pyinstaller is having trouble importing xlrd. I have tried:
--hidden-import=xlrd
and also
--hidden-import xlrd and neither has worked.
I have heard about hooks but I cannot find any documentation on how to set up the hook-xlrd.py file.
I have been getting the error:
ImportError: No Module called xlwt
The script runs perfectly from the Command Prompt.
Somehow, your application requires xlwt. So do a pip install xlwt and then add --hidden-import=xlwt to your arguments. For a more comprehensive guide, see here.

Resources