Can you run pychecker from virtualenv? - virtualenv

I want to do code analysis with pychecker but when it imports python code it doesn't use the packages from virtualenv, it uses the system wide one and the import fail.
Is there a way to install pychecker in a virtualenv or at least get it to just import the packages from the virtualenv?

Set your $PYTHONPATH environmental variable to the site-packages directory.
For me, pychecker was not able to find the configobj module. Since I use zsh (bash with lots of bells and whistles), I ran:
> find ~/venv-ops -name configobj.py
/Users/doug/venv-ops/lib/python2.7/site-packages/configobj.py
> export PYTHONPATH=/Users/doug/venv-ops/lib/python2.7/site-packages
and then pycheck worked fine.

Related

’unresolved import’ message for streamlit in Eclipse PyDev

I have successfully installed the streamlit package using the following
shell command and can run the resulting local server localhost:8501
Python3.8 -m pip install streamlit
In Eclipse, the module appears under the Package Library in the Python Interpreter.
I can import it as a library item in a PyDev module as as follows:
import streamlit
The only note I get from the compiler is that streamlit is an ‘unused import’. However, when I append the command as follows the compiler then says ‘unresloved import st’
import streamlit as st
Both ‘import streamlit’. and ‘import streamlit as st’ will not code complete.
How can I clear the ’unresolved import’ message ?
The sys.path is as follows:
/Users/davidklemitz/eclipse-workspace/streamlit
/Users/davidklemitz/eclipse-workspace/streamlit
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip
Thanks in advance for any help.
I solved the problem. Turns out it was a compound of two issues.
First the name of the PyDev module I chose was the same name as the package module name streamlit.py, installed using the following command
Python3.8 -m pip install streamlit
Second, I had a look at the PYTHONPATH under Eclipse->Preferences-> PyDev->Interpreters-> Python Interpreter where these paths were arranged as follows:
/Library/Frameworks/Python.framework/Versions/3.8/lib
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
As streamit.py was in the second and not the first, I reversed the order, restarted Eclipse, created a new PyDev project and associated development model named stream_lit.py and the code completed as expected.

"ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py" results in package not found

These are the commands that were used:
$ source /opt/ros/foxy/setup.bash
ROS_DISTRO was set to 'noetic' before. Please make sure that the environment does not mix paths from different distributions.
$ export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3_simulations/turtlebot3_gazebo/models
$ export TURTLEBOT3_MODEL=burger
$ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
Package 'turtlebot3_gazebo' not found: "package 'turtlebot3_gazebo' not found, searching: ['/opt/ros/foxy']"
Is it possible that a sub-directory is missing in the path?
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models
Alternatively, you may use the following if you do not require a workspace:
export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:/opt/ros/foxy/share/turtlebot3_gazebo/models

The inability to install the module on Python

I have a problem. When writing the "pip install pyowm" command to the console, the module is installed, but the system doesn't see it. For example, Phyton, when executing the command "impor pyowm", gives an error, and when writing the command "pyowm" to the console, the error "" pyowm " is not an external or internal command".
All of the above apply to other modules as well.
P.S. I use VS Code and Python v.3.8.3
From https://github.com/csparpa/pyowm:
from pyowm import OWM
The package name (pyowm) and the module name (OWM) do not necessarily need to correspond.
You can't just use any tool just by name from the console.
You have to first enter python to the console and then try import pyowm again.
It should import pyowm. But later you may want to actually use pyowm. Then you use this import most of the time:
from pyowm.owm import OWM

No name 'xxx' in module 'ansible.module_utils', pylint(no-name-in-module) in VScode

What cause this issue
Ansible supports user-defined module_utils folder, we can add following line in ansible.cfg:
module_utils = /xxx/lib/module_utils
Then, when the playbook running, ansible will combine both /usr/local/lib/python3.6/dist-packages/ansible/module_utils and /xxx/lib/module_utils together.
So, we can import module utilities in user-defined ansible module, like:
import ansible.module_utils.my_utils
But, pylint doesn't read the ansibe.cfg file and combine the user-defined utility folder with system one. So, it can't find my_utils in /usr/local/lib/python3.6/dist-packages/ansible/module_utils, and cause this issue.
My question
Is there any way to make the pylint 'see' the modules in user-defined folder?
BTW, add additional search path in pylint configuration like below won't fix this issue.
init-hook='import sys; sys.path.append("/xxx/lib/module_utils")'
because in ansible module, we used ansible.module_utils namespace
import ansible.module_utils.my_utils
not
import my_utils

Force py.test to use installed version of module

I have a mixed Python/C++ library with test files mixed in amongst source files in the same directories. The layout looks like
/home/irving/geode
geode
__init__.py
vector
__init__.py
test_vector.py
...
...
Unfortunately, the library is unusable in-place since it lacks .so extension modules. Question: Can I make py.test always use an installed version, even when run from /home/irving/geode or a subdirectory?
The test files have from __future__ import absolute_import, and run fine if executed directly as scripts. For example, if I do
cd geode/vector
./test_vector.py
which does import geode, it finds the installed version. However, if I run py.test in geode/vector, it finds the local copy of geode, and then dies.
I think you have two options:
run py.test --pyargs geode.vector.test_vector to make pytest interpretet the argument as an import path, deriving the file system path from it. This should run the test against the installed version.
move the tests out into a tests directory without an __init__.py file. This way you need to pip install -e . to work in-place or can do python setup.py install and the py.test tests to run tests against the installed version.