Trying to import winsound - python-3.x

When I import winsound and then try to run the program, it returns an error message saying:
ImportError: No module named 'winsound'.
Are there any settings I need to change?

winsound only exists in Python installed under Windows. Do not attempt to import it if you are not running under Windows.

Related

ModuleNotFoundError: No module named 'flask_wtf' ... verified installed in virtualenv

My import statements are as follows:
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, BooleanField, SubmitField
from wtforms.validators import DataRequired
I am able to execute the file - blank.py - within Pycharm and do not receive a ModuleNotFoundError.
Whenever I execute flask run in terminal I get ModuleNotFoundError: 'flask_wtf' and it traces back to 'blank.py'.
I am not sure why this is happening as I have both flask and flask-wtf installed globally and locally. I have never had this problem when working with other libraries.
How do I fix this? Thank you for you help.

How do I import modules that are used inside a Python 3 file?

I have the following code in myfile.py
def show_path():
print(os.getcwd())
In Jupyter notebook, I have the following (which runs fine):
import os
from myfile.py import show_path
However, when I run the following:
show_path()
I get 'name 'os' is not defined' error. But when I simply type:
os.getcwd()
I get the path, which I understand. But I don't understand why running show_path() doesn't do the same thing? Is it necessary to have import os inside my myfile.py file? If so, why?
You have to import os in your module, its import list is different then that of your notebook. Since you did not import it in your module, it wa unavailable when your module was parsed.

JupyterLab - import module

I use JupyterLab, jupyter notebook and try to import the script. The script is located in the notebook's directory.
Unfortunately import is impossible.
Error:
ImportError: No module named 'irt_01_generate_sample_data'
On the other hand:
When I run terminal and import the script, everything works fine.
What should I do to import the script ?
One thing to check is whether you're running the same Python (executable) and have the same paths (where it is looking for imports) in both the terminal and Jupyter Notebook:
import sys
sys.executable
sys.path

Python from Windows to Centos -> import msvcrt getch issue

I have a stupid question I think.
I have a script develloped on Windows but the goal is to run it on a Centos Server 7. The script work well on windows but not on Centos.
I have this error :
[root#114697 scripts]# python3.6 synch.py
Traceback (most recent call last):
File "synch.py", line 9, in <module>
from msvcrt import getch
ModuleNotFoundError: No module named 'msvcrt'
My script start with this :
from __future__ import division
import websocket
import thread
import time
import random
import sys
import json
import pymysql
import datetime
from time import ctime
from time import sleep
from msvcrt import getch
from pprint import pprint
import os
Seems msvcrt import getchcome from Microsoft ...
Can some one help to solve this problem please ?
Note : Python 3.6 is not involved, it was compiled in a clean way on the server.
Seems
Yoki
If you read the documentation for the msvcrt module, the first two sentences have this to say:
These functions provide access to some useful capabilities on Windows platforms. Some higher-level modules use these functions to build the Windows implementations of their services.
Since Centos Server 7 is not Windows, you will need to find an alternative approach to getch.
Solved ! I just remove
from msvcrt import getch
In fact in don't need to interact with the script on Centos ... it is a deamon :)

Why am I getting an AttributeError

I am trying to execute a command in linux when the file fast_dp.mtz is present. However, I get an attribute error.
import sys
import os
import time
import copy
import exceptions
import traceback
import subprocess
import os.path
from run_job import run_job
if(os.path_isfile('fast_dp.mtz')):
os.system('fast_ep sad=fast_dp.mtz')
Okay I figured out what I was doing wrong. Turns out that in Geany os.path is file command has an "_" (underscore) while my python 2.7 needed a "." (period). I just change that and the program ran fine.

Resources