When I’m writing up code in setup.py, nose module simply does not work.
I did some snooping around, and figured out, that nose is installed in (lpthw) virtual enviroment…
… but VS Code does not recognize it, and thusly, does not import it.
How can I fix this?
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.
Figured it out.
While editing setup.py and NAME_tests.py, i couldn’t simply open them in VS Code from level of Windows, I had to use
(lpthw) > code setup.py
command, so VS Code launches in restricted mode, from level of (lpthw) venv.
Unfortunately, nose still malfunctioned, so I used Pytest and everything ran correctly.
Thank you for response!
Nice, yep pytest seems to be the solution to nose.
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:
# powershell here
Either one will work. Then I can take a look.
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 list
And when I invoke pip list outside of virtual enviroment, me example-module is gone.
PS C:\Users\Adam> pip list
Then, I checked my module with pip show command:
(lpthw) PS C:\Users\Adam\.venvs\lpthw\projects\example_project> pip show example_module
Summary: example project
Home-page: URL to get it at.
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
Summary: Python Game Development
Author: A community project.
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?
Not really, you said this:
“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.
Thank you for clarifying this, Zed.
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.
Great, thank you for help!