Windows: equivalent of OS X's Terminal "&"
If you are a fan of *NIX shells, you can install Cygwin and have access to all those shells and tools with Cygwin. Ot you can just install a Bash shell with Win-Bash. However, I think you would be better off with Cygwin, as it has a lot of functionality.
Related videos on Youtube
N Lee
Updated on September 18, 2022Comments
-
N Lee over 1 year
I'm new to VS Code for python development on Windows and my pylint cannot find a package. This is my project directory structure.
workspace/ <- This is VS Code workspace (E:\workspace) .vscode/ launch.json settings.json project1/ mypackge/ __init__.py <- In here, I wrote: `import mypackage.first_sub_pkg` first_sub_pkg/ __init__.py <- In here, I wrote: `from .second_sub_pkg.mymodule import MyClass` second_sub_pkg/ __init__.py <- In here, I wrote: `from .mymodule import MyClass` mymodule.py <- This module has class: `MyClass` test_script/ mytest.py project2/ etc.../
And I wrote the mytest.py script code like:
from mypackge.first_sub_package import MyClass
I'm using C:/Anaconda3/python.exe for python interpreter
When I click the button on the upper side ▷ (Run Python File in Terminal) on the upper right side of VS Code, I get this error message
PS E:\workspace> & c:/Anaconda3/python.exe e:/workspace/project1/test_script/mytest.py Traceback (most recent call last): File "e:/workspace/project1/test_script/mytest.py", line 1, in <module> from first_sub_pkg.second_sub_pkg import MyClass ModuleNotFoundError: No module named 'first_sub_pkg'
Also, I added workspace/.vscode/launch.json like:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "pythonPath": "${command:python.interpreterPath}", "env": { "PYTHONPATH": "${workspaceFolder};E:/workspace/project1" } } ] }
And workspace/.vscode/settings.json like:
{ "python.autoComplete.extraPaths": [ "E:/workspace", "E:/workspace/project1", "E:/workspace/project1/first_sub_pkg", ], "python.pythonPath": "c:/Anaconda3/python.exe", "terminal.integrated.shell.windows": "C:/windows/System32/WindowsPowerShell/v1.0/powershell.exe", "python.linter": "pyLint", "python.linting.pylintPath": "pylint" }
And my user settings.json file is like:
{ "python.autoComplete.extraPaths": [ "E:/workspace", "E:/workspace/project1", "E:/workspace/project1/first_sub_pkg", ] }
I already ran this test script in Eclipse + pydev environment, and there was no problem running it. But somehow VSC cannot import my modules.
I seems like system path problem since it works well when I run python and append 'E:/workspace/project1' to system path (
import sys; sys.path.append('E:/workspace/project1');
), but I cannot find out how to solve the problem. (Adding system variables in Windows settings did not worked neither).What did I miss? Somebody please help me. I searched for 2 days but got nowhere.
-
Keltari over 10 yearsit didnt work? What exactly did you type?
-
Jetlef over 10 yearsThis is the command I use for each instance of Wget:
os.system('start /B bandcamp-support' +os.sep+ 'wget --tries=0 -q -O"{}" "{}"'.format(filename,URL))
@Keltari -
evilsoup over 10 yearsI don't know for sure if it does this (because I don't really use the Windows command-line), but you should consider using powershell rather than cmd.exe, since it has more features in general.
-
dave_thompson_085 over 8 yearsstackoverflow.com/questions/2554514/… indicates it's easy to start multiple processes with docs.python.org/2/library/subprocess.html#popen-objects and only hard to interact with more than one concurrently. docs.python.org/2/library/os.html#os.spawnl and v (but not other variants) is stated to also provide an 'older' way to run processes NOWAIT on both Unix and Windows
-
chue x over 8 years
-
Chase almost 4 yearsrunning the script from the terminal (as you're doing currently) should not have anything to do with vscode
-
N Lee over 2 yearsI found the exact solution that I needed. stackoverflow.com/questions/53653083/…
-
-
Jetlef over 10 yearsCygwin is interesting, but it requires a lot of DLLs... isn't there a single binary file out there? Or a way to pack it into a binary myself? Now I know why all programmers use Linux/OS X... and why everyone hates Windows. :D
-
Keltari over 10 yearsI highly recommend Cygwin, worst case you can uninstall it. Its stable and you can get all the *NIX tools you can ever want. Wget isnt part of the base package, you can search for it (get the one under web tools, which is the full application, not the Perl based implementation).
-
Jetlef over 10 yearsAh, I give up. Windows' scared another one away. I guess what I want to do can be somehow accomplished using these techniques: Wait the end of subprocesses with multiple parallel jobs, but I'd need to adapt those examples to Windows, and I'm just tired of doing this.
-
N Lee almost 4 yearsI only described the directories which I need to explain for this problem, so all the directories have meanings. Also, in the eclipseo or pycharm ide, there was NO PROBLEM running the SAME code. I guess eclipse or pycharm somehow import my projects to system paths, but VS Code don't. I just want to know how I should change the VS Code settings to fix this problem.
-
N Lee almost 4 yearsThanks for the kind answer and my bad. I do not have third_sub_pkg, but the problem I am facing is the same. The 1st solution: I already used that to-be statement (
from mypackage...
) The 2nd solution: I tried to change the PYTHONPATH in launch.json file as you told, but nothing changed. My test script still do not working. And could you be more specific about using '.' in the last sentence? -
Steven-MSFT almost 4 yearsThe solutions are separated, you just need to take one solution(just in case). If you want to import a module, you got to let python interpreter know which paths it should search, and only the package under these paths can be treated as a package. As you tried "PYTHONPATH": "${workspaceFolder};E:/workspace/project1", the python interpreter will know to search these two paths to, this means it can treat mypackage as a package, but it don't know what's meaning of first_sub_pkg, you got to tell it, it's under the package of mypackage, through 'mypackage.first_sub_pkg'.