I’m no familiar with Pylance but you should have a way of either installing nose right there in your VSCode setup, or telling it where your virtualenv is for that project. Have a look around the settings to see what you can do.
I have another quick question, but don’t want to make another thread.
I have completed all of ex46 quiz. Made some rough script in NAME folder, made a little module in bin folder, edited setup.py accordingly and managed to install it and then uninstall it with pip.
But before I move on to ex47, I wanted to test that installed module, out of curiosity.
I made another directory for 3rd project. Created a python script, where I imported my newly installed module from quiz, but when I run it in Powershell, it does not find that module (it’s present in “(lpthw) > pip list” though.
How do I fix this? And should I even bother with this at my current level, or should I move to ex47?
Hmm, that’s a tough one. You should look at your setup.py and make sure everything is filled in, but otherwise it’d take forever to debug this off the forum. Look at what it says, and also confirm that your new shell is using the original virtual env. It might be that you did this:
start virtualenv
make project
install project in virtualenv form #1
start new OS shell
pip list … BUT you’re not in virtualenv from #1 so it won’t list that
Can you delete or edit this and do a new one with pastes instead of images? I really can’t read the text in these images. You can just grab the text, copy it with the Edit menu (or hit ENTER to copy it), then come here and put it in code blocks:
First image shown that my newly crafted module (named “example_module” but minus sign appeared involuntarily) is installed in virtual enviroment, among rest of modules:
(lpthw) PS C:\Users\Adam\.venvs\lpthw\projects\example_project> pip show example_module
Name: example-module
Version: 0.1
Summary: example project
Home-page: URL to get it at.
Author: Adam
Author-email: stokaratow@gmail.com
License: UNKNOWN
Location: c:\users\adam\.venvs\lpthw\lib\site-packages\example_module-0.1-py3.9.egg
Requires: pytest
Required-by:
And compared it with some other module I have installed earlier with pip:
(lpthw) PS C:\Users\Adam\.venvs\lpthw\projects\example_project> pip show pygame
Name: pygame
Version: 2.0.1
Summary: Python Game Development
Home-page: https://www.pygame.org
Author: A community project.
Author-email: pygame@pygame.org
License: LGPL
Location: c:\users\adam\appdata\local\programs\python\python39\lib\site-packages
Requires:
Required-by:
My conclusion is, I can’t import example_module, because it’s not in main modules directory.
How can I fix this? Should I tinker with sys.path, or have I simply messed up the quiz?
“And when I invoke pip list outside of virtual enviroment, me example-module is gone.”
I think there might be a misunderstanding of what virtualenv does. This is expected behavior because your lpthw virtualenv is like a walled off garden that only has the modules you install while it’s active. In this case, you activated lpthw, then added example-module, and that’s why it’s there.
But, when you exit the lpthw virtualenv then all of the modules you added while inside there disappear. It’s kind of like a mini computer inside your computer. If you had two computers, installed Photoshop on one but not the other, then when you switch computers you’d see Photoshop “disappear” from the one where you never installed it.
So, what you need to do to see the example-module everywhere is install it while not inside any virtualenv. Then it’ll be installed in the global modules location, but I highly recommend you not do this. It’s very hard to manage this and clean it up if you mess it up, but super easy to just erase a virtualenv you borked and start again.
Okay, i uninstalled and removed everything except skeleton and started from scratch.
Copied skeleton/ and named it example_project
Within example_project\example_project created python file named “project_script_a.py”
Within bin/ folder created python script named “top_level_code.py”
Edited “setup.py”, “example_project_tests.py” accordingly to instructions in ex46, pytest shows OK, everything seems to be working.
Ran (lpthw)> python setup.py install
Within example_project\example project created another script named “testing_import.py”. In it, I imported my module from step 5 named “example_project”
Ran (lpthw)> python testing_import.py and it ran without errors.
Did I make this right this time? Did I use venv-contained module correctly?
Seems like it. If you could craft the project, install it, and from within the venv run your thing then that’s it. It does get a lot more complicated with the options but that’s the start.