Error when trying to intialize an enviroment (Pipenv)) [duplicate] - python

This question already has answers here:
What's the bad magic number error?
(15 answers)
Closed 4 years ago.
Take it easy, I'm a n00b. I get this error when I'm trying to initialize an environment to get a project going. I've scoured through many stack overflow and GitHub (Usage/request) before I decided to post here. I updated pipenv and even updated by python up to 3.7 from 3.6. I've been at it for 2 hours but I decided I may need your help.
pipenv run python3
Creating a virtualenv for this project…
Pipfile: /home/user1/Pipfile
Using /usr/bin/python3 (3.6.7) to create virtualenv…
⠙ Creating virtual environment...
✘ Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]: File "/home/user1/.local/lib/python3.6/site-packages/pipenv/cli/command.py", line 408, in run
[pipenv.exceptions.VirtualenvCreationException]: command=command, args=args, three=state.three, python=state.python, pypi_mirror=state.pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]: File "/home/user1/.local/lib/python3.6/site-packages/pipenv/core.py", line 2310, in do_run
[pipenv.exceptions.VirtualenvCreationException]: three=three, python=python, validate=False, pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "/home/user1/.local/lib/python3.6/site-packages/pipenv/core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "/home/user1/.local/lib/python3.6/site-packages/pipenv/core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]: File "/home/user1/.local/lib/python3.6/site-packages/pipenv/core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/user1/.local/lib/python3.6/site-packages/virtualenv.py", line 26, in <module>
import logging
ImportError: bad magic number in 'logging': b'\x03\xf3\r\n'
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 26, in <module>
from apt.package import Package
File "/usr/lib/python3/dist-packages/apt/package.py", line 24, in <module>
import logging
ImportError: bad magic number in 'logging': b'\x03\xf3\r\n'
Original exception was:
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/user1/.local/lib/python3.6/site-packages/virtualenv.py", line 26, in <module>
import logging
ImportError: bad magic number in 'logging': b'\x03\xf3\r\n'
Failed to create virtual environ
ment.

I think the standalone version is broken, its working for me within an existing venv
(test_123) conor#xxxxxxx:~/workspace/django-machina$ make init
pipenv install --three --dev
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing dependencies from Pipfile.lock (02d410)…
Ignoring appnope: markers 'sys_platform == "darwin"' don't match your environment
Looking in indexes: https://pypi.python.org/simple
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 75/75 — 00

Related

Python build package error- 'virtualenv' has no attribute 'cli_run'

Using Azure Databricks to build a python package. Received the following error from command:
python3 -m build
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/databricks/python3/lib/python3.7/site-packages/build/__main__.py", line 214, in <module>
main(sys.argv[1:], 'python -m build')
File "/databricks/python3/lib/python3.7/site-packages/build/__main__.py", line 206, in main
build_package(args.srcdir, outdir, distributions, config_settings, not args.no_isolation, args.skip_dependencies)
File "/databricks/python3/lib/python3.7/site-packages/build/__main__.py", line 94, in build_package
_build_in_isolated_env(builder, outdir, distributions, config_settings)
File "/databricks/python3/lib/python3.7/site-packages/build/__main__.py", line 52, in _build_in_isolated_env
with IsolatedEnvBuilder() as env:
File "/databricks/python3/lib/python3.7/site-packages/build/env.py", line 65, in __enter__
executable, scripts_dir = _create_isolated_env_virtualenv(self._path)
File "/databricks/python3/lib/python3.7/site-packages/build/env.py", line 156, in _create_isolated_env_virtualenv
result = virtualenv.cli_run(cmd, setup_logging=False)
AttributeError: module 'virtualenv' has no attribute 'cli_run'
I was able to solve the same issue (although in an AWS environment) by upgrading pip and virtualenv:
python3 -m pip install --upgrade pip virtualenv

Can't launch Jupyter Notebook ModuleNotFoundError: No module named 'resource'

I've been using Jupyter Notebook from the command line for a month now, today I didn't shut the running notebook and put my laptop to sleep for 4 hours. After turning my laptop back on I tried to run the notebook again and I'm getting the same error ever since. Please help me out.
Traceback (most recent call last):
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\utils\timing.py", line 27, in <module>
import resource
ModuleNotFoundError: No module named 'resource'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\Chinmay\AppData\Local\Programs\Python\Python38-32\Scripts\jupyter-notebook.EXE\__main__.py", line 9, in <module>
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\jupyter_core\application.py", line 270, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\traitlets\config\application.py", line 663, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\traitlets\config\application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\notebook\notebookapp.py", line 1769, in initialize
self.init_webapp()
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\notebook\notebookapp.py", line 1451, in init_webapp
self.web_app = NotebookWebApplication(
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\notebook\notebookapp.py", line 153, in __init__
settings = self.init_settings(
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\notebook\notebookapp.py", line 269, in init_settings
nbextensions_path=jupyter_app.nbextensions_path,
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\notebook\notebookapp.py", line 1120, in nbextensions_path
from IPython.paths import get_ipython_dir
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\__init__.py", line 49, in <module>
from .terminal.embed import embed
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\terminal\embed.py", line 19, in <module>
from IPython.terminal.ipapp import load_default_config
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\terminal\ipapp.py", line 30, in <module>
from IPython.core.magics import ScriptMagics
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\core\magics\__init__.py", line 21, in <module>
from .execution import ExecutionMagics
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\core\magics\execution.py", line 46, in <module>
from IPython.utils.timing import clock, clock2
File "c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\utils\timing.py", line 64, in <module>
clocku = clocks = clock = time.clock
AttributeError: module 'time' has no attribute 'clock'```
Open this file: c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\utils\timing.py
change import time to import timeit
change time.clock to timeit.default_timer
This worked for me, should work for you.
conda update --all
this working
For me this happened while trying to install some other pip libraries. Looks like one of my pip libraries got downgraded and that caused this error. So upgrading it back resolved the issue.
pip3 install --upgrade jupyter-console
pip3 install --upgrade jupyter
To solve this, I went in the file execution.py and commented the row from timing import clock. In your machine this file is in the folder:
c:\users\chinmay\appdata\local\programs\python\python38-32\lib\site-packages\IPython\core\magics\
try this:
conda update --force conda
conda update ipython
I uninsatlled and installed the jupyter from conda..Worked fine for me

Can't create and active Virtualenv in windows 10 , python 37

I am new in Python and to be coder :) I am trying to create and active virtualenv, searching for days to fix this problem but I couldn't, can you help me pls..
Thank you.
Let me show you my administrator:
Using base prefix 'c:\\users\\büşra\\appdata\\local\\programs\\python\\python37'
New python executable in C:\Users\Büşra\Desktop\Django-Virtualenv\myenv\Scripts\python.exe
Complete output from command C:\Users\Büşra\Deskt...v\Scripts\python.exe -m pip config list:
Could not import runpy module
ModuleNotFoundError: No module named 'runpy'
----------------------------------------
Traceback (most recent call last):
File "c:\users\büşra\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Büşra\AppData\Local\Programs\Python\Python37\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 793, in main
symlink=options.symlink,
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 1087, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 935, in install_wheel
_install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 964, in _install_wheel_with_search_dir
config = _pip_config(py_executable, python_path)
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 1038, in _pip_config
remove_from_env=["PIP_VERBOSE", "PIP_QUIET"],
File "c:\users\büşra\appdata\local\programs\python\python37\lib\site-packages\virtualenv.py", line 886, in call_subprocess
raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command C:\Users\Büşra\Deskt...v\Scripts\python.exe -m pip config list failed with error code 1```
On a windows machine you would activate the virtual environment as follows:
cd into the project directory, if your virtual environment is named venv then this
venv\scripts\activate will activate the virtual environment

Error with "mlflow ui" when trying to run it on MS Windows

When I run mlflow ui the following error occurred:
Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\gunicorn.exe\__main__.py", line 5, in <module>
File "c:\anaconda3\lib\site-packages\gunicorn\app\wsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "c:\anaconda3\lib\site-packages\gunicorn\app\base.py", line 12, in <module>
from gunicorn import util
File "c:\anaconda3\lib\site-packages\gunicorn\util.py", line 9, in <module>
import fcntl
ModuleNotFoundError: No module named 'fcntl'
Traceback (most recent call last):
File "c:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\mlflow.exe\__main__.py", line 9, in <module>
File "c:\anaconda3\lib\site-packages\click\core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "c:\anaconda3\lib\site-packages\click\core.py", line 697, in main
rv = self.invoke(ctx)
File "c:\anaconda3\lib\site-packages\click\core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "c:\anaconda3\lib\site-packages\click\core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "c:\anaconda3\lib\site-packages\click\core.py", line 535, in invoke
return callback(*args, **kwargs)
File "c:\anaconda3\lib\site-packages\mlflow\cli.py", line 131, in ui
mlflow.server._run_server(file_store, file_store, host, port, 1)
File "c:\anaconda3\lib\site-packages\mlflow\server\__init__.py", line 48, in _run_server
env=env_map, stream_output=True)
File "c:\anaconda3\lib\site-packages\mlflow\utils\process.py", line 38, in exec_cmd
raise ShellCommandException("Non-zero exitcode: %s" % (exit_code))
mlflow.utils.process.ShellCommandException: Non-zero exitcode: 1
I used anaconda + python 3.6.5 and I installed git and set path with C:\Program Files\Git\bin\git.exe and C:\Program Files\Git\cmd.
I installed mlflow whit pip install mlflow and its version is 0.2.1.
I set a variable with name GIT_PYTHON_GIT_EXECUTABLE and value C:\Program Files\Git\bin\git.exe in Environment Variables.
How can I solve this?
firstly Uninstall 'mlflow' and 'waitress', then again install 'mlflow' .Now try it works
mlflow documentation already says that
Note 2: We do not currently support running MLflow on Windows.
Despite this, we would appreciate any contributions to make MLflow
work better on Windows.
You're hitting fcntl problem: it's not available on MS Windows platform because it's a "wrapper" around the fcntl function that's available on POSIX-compatible systems. (See https://stackoverflow.com/a/1422436/236007 for more details.)
Solving this requires modifying the source code of mlflow accordingly.

openSSL error in Scrapy while creating project

I have just installed scrapy and all the things along with it as per from scrapy tutorial site.
When I create project using Scrapy with such command
scrapy startproject [projectname]
so it gives me following error
Traceback (most recent call last):
File "c:\python\python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python\Python27\Scripts\scrapy.exe\__main__.py", line 9, in <module>
File "c:\python\python27\lib\site-packages\scrapy\cmdline.py", line 122, in execute
cmds = _get_commands_dict(settings, inproject)
File "c:\python\python27\lib\site-packages\scrapy\cmdline.py", line 46, in _get_commands_dict
cmds = _get_commands_from_module('scrapy.commands', inproject)
File "c:\python\python27\lib\site-packages\scrapy\cmdline.py", line 29, in _get_commands_from_module
for cmd in _iter_command_classes(module):
File "c:\python\python27\lib\site-packages\scrapy\cmdline.py", line 20, in _iter_command_classes
for module in walk_modules(module_name):
File "c:\python\python27\lib\site-packages\scrapy\utils\misc.py", line 71, in walk_modules
submod = import_module(fullpath)
File "c:\python\python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "c:\python\python27\lib\site-packages\scrapy\commands\version.py", line 6, in <module>
import OpenSSL
ImportError: No module named OpenSSL
After that even I tried to install openSSl manually using pip
but it saying that package is already installed
Help me with it.
You can satisfy the missing dependency by doing the following:
You need to install OpenSSL binaries on your system. Get binaries
from here: https://wiki.openssl.org/index.php/Binaries
Then you need to install pyOpenSSL, from here: https://pypi.python.org/pypi/pyOpenSSL/0.13

Categories

Resources