Packages doesn't set up on python venv - python-3.x

I'm trying to build pyslam project, and the install.sh file was provided. But when I executed install.sh, the main.py didn't work.
https://github.com/luigifreda/pyslam#install-pyslam-under-ubuntu-2004
Full Installation
In order to run main_slam.py with venv, get in the root of this repository and run the following command:
$ . install_all_venv.sh
N.B.: do not forget the dot! (without '/' !)
This will compile the required thirdparty packages and will also activate the created pyslam environment. Now, from the same terminal, you can run:
$ python3 -O main_slam.py
The result was
(pyslam) (base) ict-526#ict526-MS-7D32:~/pyslam$ python3 -O main_slam.py
Traceback (most recent call last):
File "/home/ict-526/pyslam/main_slam.py", line 27, in <module>
from config import Config
File "/home/ict-526/pyslam/config.py", line 27, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'
I think the packages didn't install in the venv (pyslam). How can I fix this situation?
My environment is ubuntu20.04, and python 3.9.7.
According to the installaion instruction, python 3.6.9 was required. After install_all_venv.sh, the pyslam venv support python 3.9.7...

Related

How to run sagemath file in python3?

I want to run a .sagews file in python3
I have installed the sage-0.0.0 package on Ubuntu 18.04
pip3 install sage
...
...
Successfully built sage
Installing collected packages: sage
Successfully installed sage-0.0.0
according to the source
I wrote the code on the point.py file:
from sage.all import *
p = 115792089237316195423570985008687907853269984665640564039457584007908834671663
F = GF(p)
E = EllipticCurve(F, [0,7])
E.count_points(2)
I run in the terminal:
sage -python3 point.py
and I get a warning
/bin/bash: sage: command not found
I run in the terminal:
python3 point.py
and
Traceback (most recent call last):
File "point.py", line 1, in <module>
from sage.all import *
ModuleNotFoundError: No module named 'sage.all'
What exactly am I doing wrong? How can you run the sage file using python3?

Can't create virtual env with Python 3.9 in Windows

I have installed both Python 3.7 and 3.9 in my Windows 10 using Microsoft Store, which put both python files in \Users\me\AppData\Local\Microsoft\WindowsApps:
The problem is that, when I try to create a virtual env with Python 3.9 using python3.9 -m venv venv, I get this error:
Could not import runpy module
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 14, in <module>
import importlib.machinery # importlib first so we can test #15386 via -m
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\importlib\__init__.py", line 51, in <module>
_w_long = _bootstrap_external._w_long
AttributeError: module 'importlib._bootstrap_external' has no attribute '_w_long'
I read that this happens because it is trying to use pip3.7, but I can't find how to instruct python to use pip3.9.
Unset the $PYTHONPATH environment variable. That is what is causing python3.9 to incorrectly find code inside Python-3.7.
set PYTHONPATH=
python3.9 -m venv .venv

Docker, Python, and "import logging"

I have trying to build a docker image/container that is Python 3.8.2 and that will run a specific script when ran. I can get it to build but when I try and run it breaks.
Specifically, I am running into a problem where:
...
import grpc
...
gives the error:
Traceback (most recent call last):
File "/project1/script1.py", line 4, in <module>
import grpc
File "/usr/local/lib/python3.8/site-packages/grpc/__init__.py", line 23, in <module>
from grpc._cython import cygrpc as _cygrpc
File "src/python/grpcio/grpc/_cython/cygrpc.pyx", line 27, in init grpc._cython.cygrpc
File "/usr/local/lib/python3.8/asyncio/__init__.py", line 8, in <module>
from .base_events import *
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 18, in <module>
import concurrent.futures
File "/usr/local/lib/python3.8/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 42, in <module>
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: module 'logging' has no attribute 'getLogger'
HOWEVER,
if i use the
docker run -it <image name> sh
to run the image, if I try to run pip in the Docker containers command line I get the same error.
Here is the Dockerfile used to create the image:
FROM python:3.8.2
#Build the Python Environments
COPY requirements.txt /tmp/
RUN pip install -r /tmp/requirements.txt
RUN pip install "obspy==1.2.1"
#COPY project1
COPY project1 /
#Update PYTHON PATH to include project1
ENV PYTHONPATH "${PYTHONPATH}:/project1"
#Run the script1.py script
CMD python /project1/script1.py
All of this runs fine on my windows box in a Python 3.8.2 environment that contains all the packages in requirements.txt
Anyone have any suggestions on what is going on?
May be try with a different python version image.
Try mentioning the specific version of the dependency in requirements.txt file
Is there any python file named logging.py or module folder named logging in your project? If so try give it another name.

Completely confused by PyCharm environments

I managed to install an OpenAI gym Atari environment in a PyCharm project. (It took so much trial and error that I no longer know what finally got it to work. But now it does.)
I copied the project directory, created another project from the copy, and tried to run the same program that ran before -- actually the copy of the program that was created when I copied the directory. Now I get an error message saying that the Atari environment is not installed -- or not installed correctly.
Traceback (most recent call last):
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\atari\atari_env.py", line 9, in <module>
import atari_py
ModuleNotFoundError: No module named 'atari_py'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/rabbott/Google Drive/CSULA/ECST/CS Dept/CS 4660/2018/OpenAI_Models/Q-Learning-Framework - Copy/Interactive_Atari-2018-10-27-2230.py", line 416, in <module>
GameControl(Bot()).play('Pong-v0')
File "C:/Users/rabbott/Google Drive/CSULA/ECST/CS Dept/CS 4660/2018/OpenAI_Models/Q-Learning-Framework - Copy/Interactive_Atari-2018-10-27-2230.py", line 30, in play
env = gym.make(game)
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 167, in make
return registry.make(id)
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 119, in make
env = spec.make()
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 85, in make
cls = load(self._entry_point)
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py", line 14, in load
result = entry_point.load(False)
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 2324, in load
return self.resolve()
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\pkg_resources\__init__.py", line 2330, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\atari\__init__.py", line 1, in <module>
from gym.envs.atari.atari_env import AtariEnv
File "C:\Users\rabbott\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\atari\atari_env.py", line 11, in <module>
raise error.DependencyNotInstalled("{}. (HINT: you can install Atari dependencies by running 'pip install gym[atari]'.)".format(e))
gym.error.DependencyNotInstalled: No module named 'atari_py'. (HINT: you can install Atari dependencies by running 'pip install gym[atari]'.)
Process finished with exit code 1
When I try to install it again, I run into the same problems I had originally. In particular, I have no idea what will get the Atari environment installed correctly.
Is there some relatively easy and straightforward way to use the installation that already works in the copy of the project?
Thanks.
Safest way to install gym and work without any issue is by using a python virtual environment. It is always better to have a separate virtual environment for your gym projects. Please use conda or pipenv to create a virtual environment.
Example in pipenv
install pipenv
pip install --user pipenv
go inside your project directory ( where your .py file resides )
cd myproject
install gym
pipenv install gym
install atari and any other dependency in your virtual environment as follows.
pipenv install atari-py
run your code
pipenv run python main.py
This will make sure your code work without any issue.
NOTE
Pipenv creates different virtual environments for each project. If you want to use the same environment for multiple projects use virtual environments in conda as mentioned above.

Tensorflow Object Detection API / ImportError: cannot import name 'keypoint_box_coder_pb2'

I followed instructions (https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md) to install the Tensorflow Object Detection
API. I use Anaconda on Windows 10 and all of the steps in the instructions seemed to complete OK.
But when trying to run python object_detection/builders/model_builder_test.py to test the installation, I get: ImportError: cannot import name 'keypoint_box_coder_pb2'
What am I missing?
(tensorflow) C:\Users\User\Documents\GitHub\models\research>python
object_detection/builders/model_builder_test.py Traceback (most recent
call last): File "object_detection/builders/model_builder_test.py",
line 21, in
from object_detection.builders import model_builder File "C:\Users\User\New\Anaconda3\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\builders\model_builder.py",
line 18, in
from object_detection.builders import box_coder_builder File "C:\Users\User\New\Anaconda3\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\builders\box_coder_builder.py",
line 21, in
from object_detection.protos import box_coder_pb2 File "C:\Users\User\New\Anaconda3\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\protos\box_coder_pb2.py",
line 17, in ImportError: cannot import name
'keypoint_box_coder_pb2'
I got it to work. What I did was:
I ran:
protoc --python_out=. .\object_detection\protos\anchor_generator.proto .\object_detection\protos\argmax_matcher.proto .\object_detection\protos\bipartite_matcher.proto .\object_detection\protos\box_coder.proto .\object_detection\protos\box_predictor.proto .\object_detection\protos\eval.proto .\object_detection\protos\faster_rcnn.proto .\object_detection\protos\faster_rcnn_box_coder.proto .\object_detection\protos\grid_anchor_generator.proto .\object_detection\protos\hyperparams.proto .\object_detection\protos\image_resizer.proto .\object_detection\protos\input_reader.proto .\object_detection\protos\keypoint_box_coder.proto .\object_detection\protos\losses.proto .\object_detection\protos\matcher.proto .\object_detection\protos\mean_stddev_box_coder.proto .\object_detection\protos\model.proto .\object_detection\protos\optimizer.proto .\object_detection\protos\pipeline.proto .\object_detection\protos\post_processing.proto .\object_detection\protos\preprocessor.proto .\object_detection\protos\region_similarity_calculator.proto .\object_detection\protos\square_box_coder.proto .\object_detection\protos\ssd.proto .\object_detection\protos\ssd_anchor_generator.proto .\object_detection\protos\string_int_label_map.proto .\object_detection\protos\train.proto
What was missing was: .\object_detection\protos\keypoint_box_coder.proto
Then ran:
python setup.py build
python setup.py install
Then changed:
nets to research.slim.net in faster_rcnn_inception_resnet_v2_feature_extractor.py and faster_rcnn_resnet_v1_feature_extractor.py (in the models folder)
Ran:
python object_detection/builders/model_builder_test.py
Got:
Ran 11 tests in 0.195s
OK
It looks like you have not run
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim # (from tensorflow/models/research folder)
in the same terminal before launching the test, have you ? If you've chosen the .bashrc option, you probably need to reload your bshrc filewith . ~/.bashrc

Resources