tox Invocation failed for Python 3 - python

tox runs my Python 2.7 tests, but fails for Python 3.4. It gives an "Invocation failed" message. Excerpts:
py34 create: /home/josh/code/ezoutlet/.tox/py34
ERROR: invocation failed (exit code 1), logfile: /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log
ERROR: actionid: py34
msg: getenv
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
And later
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Running virtualenv with interpreter /usr/bin/python3.4
ERROR: InvocationError: /usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34 (see /home/josh/code/ezoutlet/.tox/py34/log/py34-0.log)

You need to look at the details of the error message. Notice the command that failed (from the first excerpt):
cmdargs: ['/usr/bin/python', '-m', 'virtualenv', '--python', '/usr/bin/python3.4', 'py34']
You can run this manually with:
/usr/bin/python -m virtualenv --python /usr/bin/python3.4 py34
Assuming you see the same error, your issue is with virtualenv rather than tox.
I reviewed the virtualenv help page and it seems like this should work. Faced with a possible bug, a good first step is to upgrade Python, virtualenv, or other libraries.
In my case, upgrading virtualenv was the solution:
pip install --upgrade virtualenv
Interestingly, this solution worked on both Windows and Linux. Most likely, there was a bug fix between when I got virtualenv and the latest release.

Related

Failed to import dataclasses module

Today I installed python 3.7 from apt-get to try out the new dataclasses module. I installed it seperately because python3.6 wasn't upgradeable to 3.7.
When I type: python3.7 --version, it gives me: >>> Python 3.7.0a2 as my current version.
The problem is that I can't seem to import dataclasses.
my import statement is: from dataclasses import dataclass as instructed here
This is the error message it's giving me:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dataclasses'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dataclasses'
I even tried installing the dataclasses module with pip3: pip3 install dataclasses. Not sure if that's necessary though.
Any suggestion on what might be the problem?
[EDIT] Just tried it with a python3.6 console and it worked fine .. weird.
As suggested by #wim python3.7 -m venv venv_dir
This command will:
Use python3.7 to run the command
The -m flag tells the interpreter to run the next argument as a script
venv is a module, and because of the -m flag it will be run as a script
Finally, the venv_dir is given to the venv module as an argument which
this module will use to create a virtual environment directory at
Once this command is run now you'll have a nice sandbox for messing around/testing the dataclasses module.
To activate this virtual environment be sure to run source venv_dir/bin/activate before you begin. This command will run the script at venv_dir/bin/activate to set up the necessary environment variables and other things for you
To deactivate, simply run deactivate after activating

OpenAI gym mujoco ImportError: No module named 'mujoco_py.mjlib'

I try to run this code in openAi gym. but it can not.
import mujoco_py
import gym
from os.path import dirname
env = gym.make('Hopper-v1')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample())
the error info:
/Users/yunfanlu/anaconda/envs/py35/bin/python3.5 /Users/yunfanlu/WorkPlace/OpenAIGym/OpenGymL/c.py
[2017-07-23 17:17:15,633] Making new env: Hopper-v1
Traceback (most recent call last):
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/mujoco_env.py", line 12, in <module>
from mujoco_py.mjlib import mjlib
ImportError: No module named 'mujoco_py.mjlib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yunfanlu/WorkPlace/OpenAIGym/OpenGymL/c.py", line 15, in <module>
env = gym.make('Hopper-v1')
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 161, in make
return registry.make(id)
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 119, in make
env = spec.make()
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 85, in make
cls = load(self._entry_point)
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/registration.py", line 17, in load
result = entry_point.load(False)
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py", line 2258, in load
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/setuptools-27.2.0-py3.5.egg/pkg_resources/__init__.py", line 2264, in resolve
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/__init__.py", line 1, in <module>
from gym.envs.mujoco.mujoco_env import MujocoEnv
File "/Users/yunfanlu/anaconda/envs/py35/lib/python3.5/site-packages/gym/envs/mujoco/mujoco_env.py", line 14, in <module>
raise error.DependencyNotInstalled("{}. (HINT: you need to install mujoco_py, and also perform the setup instructions here: https://github.com/openai/mujoco-py/.)".format(e))
gym.error.DependencyNotInstalled: No module named 'mujoco_py.mjlib'. (HINT: you need to install mujoco_py, and also perform the setup instructions here: https://github.com/openai/mujoco-py/.)
Process finished with exit code 1
My Computer Envs:
OS: macOS
python: python3.5 (conda envs)
I have benn install "pip install 'gym[all]'" and install mujoco.
➜ .mujoco tree
.
├── LICENSE.txt
├── mjkey.txt
└── mjpro150
I can run the examples of mujoco. it is successful.
(py35) ➜ OpenGymL python body_interaction.py
Creating window glfw
I have the same issue and it is caused by having a recent mujoco-py version installed which is not compatible with the mujoco environment of the gym package.
The issue is still open and its details are captured in #80. As commented by machinaut, the update is on the roadmap and you can use version 0.5.7 in the meantime.
pip install mujoco-py==0.5.7

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

configparser not working in Python 3.4, NoSectionError but works fine in PyCharm

I worked on a Python 3.4 script in PyCharm 4.5. (repo: https://github.com/Djidiouf/bbot )
In it, I used import configparser without any problem for retrieving some values in a config.cfg:
config = configparser.RawConfigParser()
config.read('config.cfg')
server = config.get('bot_configuration', 'server')
channel = config.get('bot_configuration', 'channel')
botnick = config.get('bot_configuration', 'botnick')
port = config.getint('bot_configuration', 'port')
Now, I want to deploy it on a Debian 8.1 server. On that server, I have both Python 2.7 and Python 3.4 versions installed.
But when I ran the script on the machine, I have the following issue:
djidiouf#linuxserver:/home/djidiouf# /usr/bin/python3.4 /home/djidiouf/bbot/bbot.py
Traceback (most recent call last):
File "/usr/lib/python3.4/configparser.py", line 1116, in _unify_values
sectiondict = self._sections[section]
KeyError: 'bot_configuration'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/djidiouf/bbot/bbot.py", line 25, in <module>
import modules.steam # Contains specific Steam-Valve related functions
File "/home/djidiouf/bbot/modules/steam.py", line 13, in <module>
import modules.connection
File "/home/djidiouf/bbot/modules/connection.py", line 37, in <module>
server = config.get('bot_configuration', 'server')
File "/usr/lib/python3.4/configparser.py", line 754, in get
d = self._unify_values(section, vars)
File "/usr/lib/python3.4/configparser.py", line 1119, in _unify_values
raise NoSectionError(section)
configparser.NoSectionError: No section: 'bot_configuration'
I made a lot of research on Internet about that but I didn't find anything valuable. Some people made mention about a corrupt config.cfg file but mine is a LF EOL file with UTF8 without BOM as needed. I also recreated it again with vi on the machine.
I also tried to install configparser with pip (even if, if I understand it well, it's now build-in in Python 3) : pip3 install configparser But when I do that, I have the following error:
djidiouf#linuxserver:/home/djidiouf# sudo pip3 install -v configparser
[sudo] password for djidiouf:
Downloading/unpacking configparser
Ignoring link https://pypi.python.org/packages/source/c/configparser/configparser-3.5.0b1.tar.gz#md5=d60ca2c714acb4adaf5818c6a1ffd78b (from https://pypi.python.org/simple/configparser/), version 3.5.0b1 is a pre-release (use --pre to allow).
Ignoring link https://pypi.python.org/packages/source/c/configparser/configparser-3.5.0b2.tar.gz#md5=ad2a71db8bd9a017ed4735eac7acfa07 (from https://pypi.python.org/simple/configparser/), version 3.5.0b2 is a pre-release (use --pre to allow).
Using version 3.3.0r2 (newest of versions: 3.3.0r2, 3.3.0r1, 3.2.0r3, 3.2.0r2, 3.2.0r1)
Downloading configparser-3.3.0r2.tar.gz
Downloading from URL https://pypi.python.org/packages/source/c/configparser/configparser-3.3.0r2.tar.gz#md5=dda0e6a43e9d8767b36d10f1e6770f09 (from https://pypi.python.org/simple/configparser/)
Running setup.py (path:/tmp/pip-build-v7av3db7/configparser/setup.py) egg_info for package configparser
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 5, in <module>
import distutils.core
File "/usr/lib/python3.4/distutils/core.py", line 18, in <module>
from distutils.config import PyPIRCCommand
File "/usr/lib/python3.4/distutils/config.py", line 7, in <module>
from configparser import ConfigParser
File "/tmp/pip-build-v7av3db7/configparser/configparser.py", line 397
_KEYCRE = re.compile(ur"%\(([^)]+)\)s")
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 5, in <module>
import distutils.core
File "/usr/lib/python3.4/distutils/core.py", line 18, in <module>
from distutils.config import PyPIRCCommand
File "/usr/lib/python3.4/distutils/config.py", line 7, in <module>
from configparser import ConfigParser
File "/tmp/pip-build-v7av3db7/configparser/configparser.py", line 397
_KEYCRE = re.compile(ur"%\(([^)]+)\)s")
^
SyntaxError: invalid syntax
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-v7av3db7/configparser
Exception information:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 290, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/usr/lib/python3/dist-packages/pip/req.py", line 1230, in prepare_files
req_to_install.run_egg_info()
File "/usr/lib/python3/dist-packages/pip/req.py", line 326, in run_egg_info
command_desc='python setup.py egg_info')
File "/usr/lib/python3/dist-packages/pip/util.py", line 716, in call_subprocess
% (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-v7av3db7/configparser
Storing debug log for failure in /root/.pip/pip.log
Here is a config example, I just changed the values and rename the file accordingly to config.cfg :
[bot_configuration]
server = your.irc.server.com
channel = ##your_channel
botnick = bbot
port = 6667
admins = You,Him
https://github.com/Djidiouf/bbot/blob/master/config_example.cfg
Finally, I just want to say that everything is working on PyCharm 4.5, I just made a git clone, rename the config_example.cfg, change the values, tried to run the script with Python 3.4.
The install error is from _KEYCRE = re.compile(ur"%\(([^)]+)\)s"), that is causing a syntax error as the ur prefix is not supported in python3, pip is trying to instal a python2 package.
Your first error is a keyError 'bot_configuration' which is not because of not having configparser installed, configparser is part of the standard library.
The bot_configuration KeyError is because python cannot find your config file, if you use config.read('foobar') in pycharm you will see the exact same output
I figured out that I had some inconsistency about running the script. When I was in another folder than my script, nothing worked but when I was in it, it worked. Perhaps because the config file is shared and used in the main script and in a module.
In fact it's due to the need to have an absolute path in config.read('/some/path/file.cfg')
Finally, I find that answer: https://stackoverflow.com/a/13800583/3301370
So here is the solution in the case of config.cfg being on the project root directory /config.cfg :
/bbot.py
import os
config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'config.cfg'))
However, as the config file is shared and used in the main script and in a subpath, module, a correct path must be set for the sub module too:
/modules/connection.py
import os
config.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'config.cfg'))
It works fine in PyCharm because when you hit the run button for your script, it runs it with the path of the project. The fact that having a relative path for both config.read() statements worked only because of that.
The problem with installing configparser with pip is unrelated to that specific problem and can be ignore in that case as configparser is a built-in library in Python3.

Cannot install html package with pip in virtualenv

In my root project folder I have created a virtual environment for python 3.4 using the following commands:
$ virtualenv -p /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 venv
$ source venv/bin/activate
Now I would like to install some packages with pip only for this project and I do:
$ venv/bin/pip install html
And I get the following error (full traceback except I have replaced path with '...'):
Collecting html
Using cached html-1.16.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File ".../venv/lib/python3.4/site-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extension import Extension
File ".../venv/lib/python3.4/site-packages/setuptools/extension.py", line 8, in <module>
from .dist import _get_unpatched
File ".../venv/lib/python3.4/site-packages/setuptools/dist.py", line 16, in <module>
from setuptools.depends import Require
File ".../venv/lib/python3.4/site-packages/setuptools/depends.py", line 6, in <module>
from setuptools import compat
File ".../venv/lib/python3.4/site-packages/setuptools/compat.py", line 44, in <module>
from html.entities import name2codepoint
ImportError: No module named 'html.entities'; 'html' is not a package
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/xz/15p_y6cn09bdc55vkvx6vrd80000gn/T/pip-build-lgl2qvpz/html
Note that I can install this package without problems globally for python 2.7.5 which is the default version on my mac.
The package I am trying to install is this one:
https://pypi.python.org/pypi/html/1.16
This package is obsolete not compatible with current packaging tools, its last release was more than 8 years ago. I really doubt that packages published so long time ago are still usable with recent python(s).

Categories