'no module found' error in Python 3.9 for windows 10 - import

I'm a total beginner in Python, I'm reading 'Learning Python' by Mark Lutz and following along in the book. I created a file called 'script1.py', saved as an 'all files' (as opposed to a .txt file) in notepad. The name of the file, code, etc. is verbatim to that which the book instructs.
I know script1.py is there and works, I know this because when I enter 'py script1.py' in my command prompt or git bash, it correctly outputs the product of the code.
The book instructs me to run 'import script1' in Python. When I do, I get the 'module not found' error. I've tried importing as stated above, a from-import command, moving 'script1' to and from different directories. I confirmed my PATH was set up to support python, nothing.
It seems (to my UNtrained eye anyway) that python isn't finding my files. Any and all help would be greatly appreciated. Thank you.

Remember that you can only import python files into a python program. In your File Explorer, make sure that file extensions are shown and verify that your script is script1.py and not script1.py.txt or something of that sort.

Related

VSCode Cannot Execute Julia FIles

I've scoured other forums that talk about this problem and have tried all of the recommendations I've found, but I cannot seem to get VSCode to recognize my Julia.exe path and execute commands in a .jl file. Every time I run even a simple .jl file, I get /bin/sh: julia: command not found (pictured below).
I have ensured that the executable path is set properly in the .json file, and have tried moving the executable to other locations (using an M1 Mac), but it seems it still cannot find/recognize the Julia.exe:
I have even tried just pointing to the binary folder /bin, and /bin/julia.exe (with the extension), and though VSCode does not generate the error when it cannot confirm the .exe path, the actual code still generates the error above.
I'm at my wits end here. I'm sure it's a simple answer that someone could spot in a second, or know the troubleshooting for, but I've never had this issue to this degree before with installing other languages like Kotlin. Any help is greatly appreciated.
Problem was fixed by the MacOS recommendation found here:
julialang.org/downloads/platform/#optional_add_julia_to_path
Copying the binary .exe elsewhere (outside of /Applications) and changing the executable path in VSCode fixed the issue.

.py files start giving import error out of nowhere

I'm importing some python files in my colab using from 'xxx ' import 'xxx' , but sometimes it stop being recognized even if I don't do any change in the code
Example of the error message:
enter image description here
It may be that you have two different installations of python installed. There may have been an issue deleting an old version of the Python environment when you updated, or you downloaded the Microsoft Store installation and have both at the same time which could cause issues.
I've had this issue before, and it was mainly because I was running the file wrong. When you run a file, it adds the file directory to sys.path, which is where it stores package directories. If you are not running the main file, and instead you are running the file individually, that might be the issue. This can be solved by using sys.path.append() or just running the program from the main file. (I might have misunderstood the question so I apologize if this doesn't help)

Lua Modules visual studio code?

I am losing my mind here,
I am very new to Lua scripting and going through a few tutorials.
I am now learning about calling a module in Lua, but I have issues with running a "request" command.
namely (and what I have gathered from researching the problem for like 3 days to no avail)
I have set up my package.path ( and subsequently the repository that lua is using to search for module files) in a separate folder that I am calling on for this module. (Got that part!)
What I am not understanding however is how to add to the path.package in a way that will search for a file outside of that given repository, and doing this using Vs Code.
Again, I am still very new to both lua as well as vs code. But so far I have been following along and understanding it pretty well, but I seem to have hit a road block.
"Any help here would be hot!" - Jar jar
P.S
Here is a look at the error I am getting in the terminal, but I am fairly sure it is just explaining what I already mentioned about how Lua is searching for the module in a different location than I have set it too:
Executing task: lua54 C:\Users\Me\Desktop\LearningLua\Lua-Course_#2\Lesson_16\modules.lua <
lua54: ...\Desktop\LearningLua\Lua-Course_#2\Lesson_16\modules.lua:1: module 'myModule' not found:
no field package.preload['myModule']
no file 'C:\Users\Me\lua\lua\myModule.lua'
no file 'C:\Users\Me\lua\lua\myModule\init.lua'
no file 'C:\Users\Me\lua\myModule.lua'
no file 'C:\Users\Me\lua\myModule\init.lua'
no file 'C:\Users\Me\lua\..\share\lua\5.4\myModule.lua'
no file 'C:\Users\Me\lua\..\share\lua\5.4\myModule\init.lua'
no file '.\myModule.lua'
no file '.\myModule\init.lua'
no file 'C:\Users\Me\lua\myModule.dll'
no file 'C:\Users\Me\lua\..\lib\lua\5.4\myModule.dll'
no file 'C:\Users\Me\lua\loadall.dll'
no file '.\myModule.dll'
no file 'C:\Users\Me\lua\myModule54.dll'
no file '.\myModule54.dll'
stack traceback:
[C]: in function 'require'
...\Desktop\LearningLua\Lua-Course_#2\Lesson_16\modules.lua:1: in main chunk
[C]: in ?
The terminal process "C:\WINDOWS\System32\cmd.exe /d /c lua54 C:\Users\Me\Desktop\LearningLua\Lua-Course_#2\Lesson_16\modules.lua" failed to launch (exit code: 1).
so again just wanna know how to set it up to search through the new folder.
Here is an image of my edit to vs code lua path setting.... (maybe this will help understand how lost I am here)
Me Lost in The Coding Woods

Doxygen failed to run html help compiler, hhc.exe error HHC5010 when running from folder that has a parent folder that starts with "."

I am using Conan package manager on Windows to create a package. The conan command to create the package copies files to a folder within %USERPROFILE%\.conan (or C:\Users\xxxxxxx\.conan). Then from this location it builds a Visual Studio project and ultimately calls doxygen.exe to create a .chm help file in a post-build command. The doxygen command fails with:
error : failed to run html help compiler on index.hhp
Further investigation reveals the hhc.exe command executed by doxygen is failing with:
C:\Users\xxxxxxx\.conan\data\Module\1.0.0\user\channel\build\524dc97e4a3dd1f774ea3897f9e4faf26c5457d2\Documentation>"C:/Program Files (x86)/HTML Help Workshop/hhc.exe" html\index.hhp
HHC5010: Error: Cannot open "C:\Users\xxxxxxx\data\Module\1.0.0\user\channel\build\524dc97e4a3dd1f774ea3897f9e4faf26c5457d2\Documentation\html\Module.chm". Compilation stopped.
Close inspection reveals that in the error message, the ".conan" folder is missing. Sure enough, I confirmed that hhc.exe fails when the index.hpp resides in a folder that has a parent folder that starts with a ".".
Attempts to resolve this:
changing the Doxyfile setting OUTPUT_DIRECTORY to "$(TMP)/DoxygenModule" resolves the error, but creates the .chm file in another location, which I do not prefer.
navigating to the 8DOT3 name of the ".conan" folder, which is "CONAN~1", to run the hhc.exe command, succeeds, but unfortunately I have no way of getting conan to use this 8DOT3 path for creating the package. E.g. C:\Users\xxxxxxx\CONAN~1\...
I can live with the using the %TMP% folder but would prefer generating the .chm in the current folder. Anyone have any ideas?
HTML Help Workshop v1.31 is installed on my machine at C:\Program Files (x86)\HTML Help Workshop, probably from a Visual Studio installation (not sure). I attempted using a version downloaded from Microsoft website (v1.30) as well, which made no difference.
Other info: Conan version 1.18.0, Doxygen version 1.8.14, Windows 10 Version 1809
Unfortunately not a solution, but this is a known limitation in the hhc.exe, see: https://social.msdn.microsoft.com/Forums/en-US/0681145c-223b-498c-b7bf-be83209cbf4e/issue-with-html-workshop-in-a-windows-container?forum=visualstudiogeneral
HTML Help 1.x command line compiler hhc.exe cannot compile CHM file to folder whose full path contains folder name starting with dot. If you have that problem, you probably specified output path with folder starting with dot, e.g. "d:\My files.NET\documentation". You can use dots in folder names but not at the beginning.
Edit 2019-11-15:
I've just pushed a proposed patch to github (pull request 7402, https://github.com/doxygen/doxygen/pull/7402).
This proposed patch changes inside doxygen from the current directory to the short named current directory, but just for the HTML Help compilation.
Edit 2019-11-16:
Code has been integrated in the master version on github.
This is not an answer either. Actually, you found the answer and workaround[s] yourself.
Use OUTPUT_DIRECTORY to specify a directory containing no folder names beginning with periods.
The error you described is a known issue of the MS HTML Help compiler. More general, the HTML Help compiler does not like some folder and file names. Try and stick with these characters _, a..z, A..Z, 0..9. Do not use these signs in particular ., -, # .
Please note that the proprietary CHM file format is about 20 years old (Windows 95, ...). HTML Help is in maintenance mode, which means no new features and bug fixes are expected for either the runtime or the compiler. All mainstream development on HH has stopped.
There is no way to avoid this error if a directory name above begins with a period. Not even if only the necessary files are written by Doxygen and compiling of the index.hhp is done by a third-party tool like FAR HTML using your path that contains .conan. This is because all applications are using the faulty HHA.dll.
The above applies of course to the entire workflow you have described. Maybe you can interrupt it.
Doxygen can be configured not to call the HTMLHelp compiler. Just uncheck the GENERATE_HTMLHELP option (DoxyWizard: Experts > Topics > HTML). You have all files generated by Doxygen in your preferred output directory - but of course without the CHM file. This can be imported later e.g. by HelpNDoc and compiled as a CHM file in another location.
If you can interrupt the workflow and can also make changes to Doxygen's settings, then a preference setting of OUTPUT_DIRECTORY to e.g. C:/CacheMenu/CONAN~1/DOXYGE~1 also works as expected (here used as test case).
No matter what you do, your workaround and copy and paste from another directory outside is a quick solution at this stage. Please note the EDIT in #albert's answer.

Powershell dot sourcing opens up file in notepad

Everytime i dot source a file in PowerShell it opens a copy of the file in notepad.
Exe:
.\MyScript.ps1
The script runs fine - its just really annoying having these pop up all the time. Is there a way to suppress this?
I'm on windows 7 x64 and using the latest version of PowerShell.
Ex2: This is still launching notepad.
cls
Set-Location "\\PSCWEBP00129\uploadedFiles\psDashboard\"
. .\assets\DCMPull\Powershell\SqlServerTransfer.psm1
. .\assets\DCMPull\Powershell\RunLogging.psm1
You cannot dot source PowerShell files with the .psm1 file extension. One option is to rename them to .ps1.
Alternatively (and, in my opinion the better approach), you can load the PowerShell modules using Import-Module <module.psm1>. Just note that the behavior of Import-Module is different from dot sourcing it. Dot sourcing runs the script in the current scope and also persists all variables, functions, etc.in the current scope. Import-Module does not do that.
Although not very common, you can also export variables from modules with Export-ModuleMember.
Adding to Raziel's answer, there's a lot of thought that went into only being able to dot source files with .ps1 extension, and otherwise why it tries to run it as a system executable. Here's a snippet from PeterWhittaker on GitHub:
. ./afile would only execute something if there's either an
extension-less but executable aFile in the current dir, or a
(not-required-to-be-executable) afile.ps1 file, with the former taking
precedence if both are present; if the file exists, but is neither
executable nor has extension .ps1, it is opened as if it were a
document.
. <filename> with <filename> being a mere name (no path component) by
(security-minded) design only ever looks for a file of that name in
the directories listed in $env:PATH (see below), not in the current
directory.
I encountered exactly the same situation : If the point source imports the .psm1 file, the file will be opened directly instead of importing the code in the file.
Because the function of point source import is only valid in the file with suffix of.ps1, if the suffix does not meet the requirements, it will not be regarded as path, but as a code , so it is like running the corresponding string directly, and the effect is naturally to open the file.
So,this phenomenon is not aimed at .PSM1,if you change the extension to TXT, it will have the same effect. It will have the same effect for any file whose suffix is not .PS1.
You can bypass this problem by creating symbolic links or hard links!
In PowerShell 7, it's easy to create links using New-Item.