I was trying to use virtualenv to switch between python versions before learning that I could use both python and python3 on my Mac.
I was able to fix my python 2.7 version so that still works fine however, now when I run python3, I get this error:
Failed to import the site module
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 125, in <module>
import functools
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/usr/local/lib/python2.7/site-packages/reprlib/__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've looked online for this error but most of the conversation was on fixing up the patch and then upgrading virtualenv. However, this still doesn't fix my issue.
python3 -V: Python 3.6.0
virtualenv --version: 15.1.0
env | egrep -i 'python|virtualenv': PYTHONPATH=/usr/local/lib/python2.7/site-packages:
Your environment contains PYTHONPATH=/usr/local/lib/python2.7/site-packages
This doesn't work with Python 3 for obvious reasons. To remove it:
unset PYTHONPATH
I solved my problem with below command
sudo pip install virtualenv --upgrade
virtualenv -p python3 env
Related
I have coded a mathematical model and want to solve it using DOCPLEX module. My interpreter is Python 3.7. However, after doing a lot of effort, I will face the following error:
Traceback (most recent call last):
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 290, in get_cplex_module
import cplex ##UnresolvedImport
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\__init__.py", line 44, in <module>
from .aborter import Aborter
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\aborter.py", line 13, in <module>
from ._internal import _procedural as _proc
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\__init__.py", line 20, in <module>
from . import _list_array_utils
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\_list_array_utils.py", line 14, in <module>
from . import _pycplex as CPX
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\_pycplex.py", line 13, in <module>
from . import _pycplex_platform
File "C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.8\x64_win64\cplex\_internal\_pycplex_platform.py", line 22, in <module>
from cplex._internal.py37_cplex2010 import *
ModuleNotFoundError: No module named 'cplex._internal.py37_cplex2010'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/xxx/PycharmProjects/pythonProject/EPC _LTC.py", line 11, in <module>
mdl = Model("LTC")
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\model.py", line 398, in __init__
self._environment = self._make_environment()
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\model.py", line 174, in _make_environment
env = Environment.get_default_env()
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 427, in get_default_env
Environment._default_env = Environment.make_new_configured_env()
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 422, in make_new_configured_env
return Environment(start_auto_configure=True)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 84, in __init__
self.auto_configure(logger=logger)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 220, in auto_configure
self.check_cplex(logger=logger)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 328, in check_cplex
cplex = self.get_cplex_module(logger=logger)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 314, in get_cplex_module
cplex = load_cplex_from_cos_root(loc) if loc else None
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 286, in load_cplex_from_cos_root
return load_cplex(full_path, version=version)
File "C:\Users\xxx\PycharmProjects\pythonProject\venv\lib\site-packages\docplex\mp\environment.py", line 261, in load_cplex
raise FileNotFoundError("Could not load module from %s" % module_location)
FileNotFoundError: Could not load module from C:\Program Files\IBM\ILOG\CPLEX_Studio201;C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64;C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python\3.7\x64_win64\cplex;\cplex\python\3.7\x64_win64\cplex\__init__.py
I have already run the following codes in my Pycharm's terminal:
cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python
python setup.py install
or
cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\python
python setup.py install --home C:\Users\xxx\PycharmProjects\pythonProject\venv\Lib\site-packages\cplex
Finally, I also set the path variables of my own username to something like below:
"C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\python\3.6\x64_win64" and
"C:\Program Files\IBM\ILOG\CPLEX_Studio129\cplex\bin\x64_win64\cplex.exe"
In my case I upgraded to python 3.8 and solved the issue
or you can use this:
pip install docplex==2.15.194
The problem is that python setup.py install does not guaranty that the python interpreter you are using is the same as your virtual env.
You need to activate your env before you run the install script.
Please open a Terminal then run:
C:\Users\xxx\PycharmProjects\pythonProject\venv\Scripts\activate
Then you can
cd C:\Program Files\IBM\ILOG\CPLEX_Studio201\cplex\python
pip install .
Docplex has a check_list.py script, which helps diagnose presence and location of cplex versions. In a terminal where Python is present, type
$ python -m docplex.mp.check_list
The answer looks like:
* system is: Windows 64bit
* Python version 3.7.8, located at: C:\python\anaconda2020.02\envs\docplex37\python.exe
* docplex is present, version is 2.20.204
* CPLEX library is present, version is 12.10.0.0, located at: C:\OPTIM\cplex_distrib\cplex1210R0\python\3.7\x64_win64
* pandas is present, version is 1.1.4
From the check list output you posted, I can see that you installed cos201.
Docplex need the Python/Cplex interface located inside cos, in your case:
C:/Program Files/IBM/ILOG/CPLEX_Studio201/cplex/python/3.7/x64_win64
This path should be added as a content root in your Pycharm project (File/Settings/Project Structure -> add content root
To check this, open a Python console tab in Pycharm, and try
import cplex
Once you add the right path , this should work.
You can then run the check list from within the console:
from docplex.mp.check_list import run_docplex_check_list
run_docplex_check_list()
Once this works, your program should solve OK inside Pycharm.
This said, I see your version of docplex is 2.15, which is older than CPLEX 20.1. You should update DOcplex to the latest version, which is compatible with CPLEX 20.1.
I'm trying to open a mysql database on windows 10, with anaconda (python 3.7 64 bit) and the pymysql package.
From windows command prompt, I do the following :
import pymysql
db = pymysql.connect(host='localhost', user='tester', passwd='xxxx', port=3306, db='mydb')
Username, password and port are correct; the host should be localhost (I get the same error if I pass 127.0.0.1); but I get the following error, which at the end states that it can't find the ffi package:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\programs\Anaconda3\lib\site-packages\pymysql\__init__.py", line 94, in Connect
return Connection(*args, **kwargs)
File "C:\programs\Anaconda3\lib\site-packages\pymysql\connections.py", line 327, in __init__
self.connect()
File "C:\programs\Anaconda3\lib\site-packages\pymysql\connections.py", line 598, in connect
self._request_authentication()
File "C:\programs\Anaconda3\lib\site-packages\pymysql\connections.py", line 873, in _request_authentication
auth_packet = _auth.caching_sha2_password_auth(self, auth_packet)
File "C:\programs\Anaconda3\lib\site-packages\pymysql\_auth.py", line 252, in caching_sha2_password_auth
data = sha2_rsa_encrypt(conn.password, conn.salt, conn.server_public_key)
File "C:\programs\Anaconda3\lib\site-packages\pymysql\_auth.py", line 132, in sha2_rsa_encrypt
rsa_key = serialization.load_pem_public_key(public_key, default_backend())
File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\backends\__init__.py", line 15, in default_backend
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 53, in <module>
from cryptography.hazmat.bindings.openssl import binding
File "C:\programs\Anaconda3\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 13, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: DLL load failed: The specified module could not be found.
I've seen that conda navigator (nor pip) doesn't see an ffi package from its standard channels.
I have already tried this suggestion (adding the conda-forge channel) :
conda config --add channels conda-forge
conda install libffi
but conda takes forever in "solving environment" and doesn't give answers in reasonable time.
What am I supposed to do to install ffi and being able to connect to the db ? Am I the first in the world in calling mysql from python/Anaconda on windows ? I suppose there must be a solution.
Thanks, Marco
I ran into the same problem. Here's what solved it for me:
1. pip uninstall scrapy
2. conda uninstall scrapy
3. pip install --force --upgrade scrapy
4. scrapy startproject dingding
It works.
I got similar error:
File "/root/ncs/bootloader/mcuboot/scripts/imgtool.py", line 22, in <module>
main.imgtool()
File "/usr/lib/python3.7/site-packages/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/lib/python3.7/site-packages/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/lib/python3.7/site-packages/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3.7/site-packages/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/root/ncs/bootloader/mcuboot/scripts/imgtool/main.py", line 111, in getpub
key = load_key(key)
File "/root/ncs/bootloader/mcuboot/scripts/imgtool/main.py", line 74, in load_key
key = keys.load(keyfile)
File "/root/ncs/bootloader/mcuboot/scripts/imgtool/keys/__init__.py", line 52, in load
backend=default_backend())
File "/usr/lib/python3.7/site-packages/cryptography/hazmat/backends/__init__.py", line 14, in default_backend
from cryptography.hazmat.backends.openssl.backend import backend
File "/usr/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 6, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "/usr/lib/python3.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 113, in <module>
from cryptography.hazmat.bindings.openssl import binding
File "/usr/lib/python3.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 14, in <module>
from cryptography.hazmat.bindings._openssl import ffi, lib
ImportError: this module was compiled for Python 3.5
Solution:
Search _cffi_backend.cpython*.so in /usr/lib and /usr/local/lib
Kill these _cffi_backend.cpython*.so
Search cffi directories in /usr/lib and /usr/local/lib
Kill these directories
pip3 install --force-reinstall cryptography
new to coding and I think I've searched thoroughly for answers to this question, but the suggested solutions haven't been working for me. Apologies if this is a duplicate, though!
I'm trying to set up my computer according to these instructions, currently trying to get virtualenv up and running. However, pip doesn't seem to be working properly. I was able to use python -m pip as a workaround and installed virtualenv using: python -m pip install virtualenv
But the same workaround doesn't seem to work with virtualenvwrapper: python -m pip install virtualenvwrapper gives me this error:
Exception:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run
requirement_set.prepare_files(finder)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 634, in _prepare_file
abstract_dist.prep_for_dist()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 412, in run_egg_info
self.setup_py, self.name,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/req/req_install.py", line 387, in setup_py
import setuptools # noqa
File "/Library/Python/2.7/site-packages/setuptools/__init__.py", line 12, in <module>
import setuptools.version
File "/Library/Python/2.7/site-packages/setuptools/version.py", line 1, in <module>
import pkg_resources
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 72, in <module>
import packaging.requirements
File "/Library/Python/2.7/site-packages/packaging/requirements.py", line 59, in <module>
MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly 2 arguments (1 given)
If I try running anything directly with a pip command, such as pip install virtualenvwrapper, I get this error:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/Library/Python/2.7/site-packages/pkg_resources/__init__.py", line 72, in <module>
import packaging.requirements
File "/Library/Python/2.7/site-packages/packaging/requirements.py", line 59, in <module>
MARKER_EXPR = originalTextFor(MARKER_EXPR())("marker")
TypeError: __call__() takes exactly 2 arguments (1 given)
I have a mac running Sierra (10.12.4). Python version 2.7.6. Pip 9.0.1
Thoughts? Thank you!
I am trying to get Fab up and running locally. Why is Fab installing to /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5? The system Python version is 2.7.10, confirmed below:
Toms-MBP:~ tom$ which python
/usr/local/bin/python
Toms-MBP:~ tom$ python --version
Python 2.7.10
Toms-MBP:~ tom$ head -1 `which fab`
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
Toms-MBP:~ tom$ fab
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/bin/fab", line 9, in <module>
load_entry_point('Fabric==1.11.1', 'console_scripts', 'fab')()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
return ep.load()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2355, in load
return self.resolve()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2361, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/fabric/main.py", line 13, in <module>
from operator import isMappingType
ImportError: cannot import name 'isMappingType'
you need this:
pip install fabric3
Its look like you aren't using a virtualenv configured previously, so I think that the system just uses the normal path to python which means to /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 .
This error is usual when we try use Fabric with python3.x because Fabric has not been update to this version of python which is really sad.
I've been getting error bringing up Scrapy on my Linux box. I'm using Ubuntu 14.0 Desktop. I've installed setuptools and scrapy. For some reason when I put
scrapy --version
I get this error:
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 11, in <module>
sys.exit(execute())
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 122, in execute
cmds = _get_commands_dict(settings, inproject)
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 46, in _get_commands_dict
cmds = _get_commands_from_module('scrapy.commands', inproject)
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 29, in _get_commands_from_module
for cmd in _iter_command_classes(module):
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 20, in _iter_command_classes
for module in walk_modules(module_name):
File "/usr/local/lib/python2.7/dist-packages/scrapy/utils/misc.py", line 68, in walk_modules
submod = import_module(fullpath)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/scrapy/commands/bench.py", line 2, in <module>
from scrapy.tests.spiders import FollowAllSpider
ImportError: No module named tests.spiders
Any Idea what would this be from?
There was an issue with build 0.24.3 commited on Github.
To solve your problem just type this in terminal:
sudo pip install scrapy --upgrade
This will upgrade your version of Scrapy to 0.24.4.
Referring to the stackoverflow.com/q/25218633/190597. That will fix the issue. Or at least in my case.
Try uninstalling the old version of scrapy with:
pip uninstall Scrapy
and then installing it again using pip with this command:
pip install scrapy==0.24.2
well do not forget to install python development packages beforehand. That will raise another issue if not installed properly.